using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Data;
using System.Drawing;
using System.Reflection;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using OpenComposite.Base.Designer;
using OpenComposite.EII.Designer;
using OpenComposite.EII.Designer.BObjects;
using OpenComposite.EII.Designer.BusinessProcess;
using OpenComposite.EII.Designer.BUSView;
using OpenComposite.EII.Designer.Generic;
using OpenComposite.EII.Designer.Org;
using OpenComposite.EII.Designer.SCA;
using OpenComposite.Repository.Properties;
using OpenComposite.EII.Repository;
using OpenComposite.EII.RepositoryUIs;
using WeifenLuo.WinFormsUI.Docking;
using OpenComposite.EII.Services;
using System.Drawing.Design;
using System.Diagnostics;
using System.Xml.Serialization;
using Microsoft.Win32;
using OpenComposite.Forms;
using OpenComposite.Workflow;
using OpenComposite.Base.Collections;
using OpenComposite.Repository.Forms.TrackingMonitor;

namespace OpenComposite.EII
{
	public class RepositoryService : IServiceProvider, Services.IRepositoryChangeService
	{
		#region Initialization
		public RepositoryService(RepositorySurfaceManager surfaceManager)
		{
			_surfaceManager = surfaceManager;

			_items = new Dictionary<RepositoryItemKey, IRepositoryItem>();
			_lstController = new List<IController>();

			this.Mode = RepositoryMode.Complete;

			#region static events
			WorkflowHelpers.AssignWorkflow += new EventHandler(WorkflowHelpers_AssignWorkflow);
			#endregion

			//initRepositoryItemUIs();
			//initPropertyDialogs();
		}
		#endregion

		#region Create RepositoryItemBase Objects

		/// <summary>
		/// Gets a new repository item.
		/// </summary>
		/// <param name="type">The type.</param>
		/// <param name="bShowInputDialog">if set to <c>true</c> [b show input dialog].</param>
		/// <param name="parentItem">The parent item.</param>
		/// <returns></returns>
		public IRepositoryItem GetNewItem(ItemType type, bool bShowInputDialog,
											 ref IRepositoryItem parentItem)
		{
			bool bSC;
			IRepositoryItem item = createItem(type, true, bShowInputDialog,
				Global.Status.CurrentRepositoryId, false, ref parentItem, out bSC);
			if ( item != null ) {
				addItem(item);
				if ( type == ItemType.Domain || parentItem != null ) {
					// add item to hierarchy
					// only domains could be top level elements (parentItem == null)
					Global.Data.AddRepositoryHierarchy(parentItem, item, Global.Status.CurrentRepositoryId);
				}
			}
			return item;
		}
		public IRepositoryItem GetNewItem(ItemType type, bool bShowInputDialog,
											 ref IRepositoryItem parentItem, out bool bSaveContinue)
		{
			IRepositoryItem item = createItem(type, true, bShowInputDialog,
				Global.Status.CurrentRepositoryId, true, ref parentItem, out bSaveContinue);
			if ( item != null ) {
				addItem(item);
				if ( type == ItemType.Domain || parentItem != null ) {
					// add item to hierarchy
					// only domains could be top level elements (parentItem == null)
					Global.Data.AddRepositoryHierarchy(parentItem, item, Global.Status.CurrentRepositoryId);
				}
			}
			return item;
		}
		public IRepositoryItem GetItem(ItemType type, bool bCreateNew, int idRepository)
		{
			bool bSC;
			IRepositoryItem parentItem = null;
			IRepositoryItem item = createItem(type, bCreateNew, true, idRepository, false, ref parentItem,
												 out bSC);
			if ( bCreateNew ) {
				addItem(item);
			}
			return item;
		}
		public IRepositoryItem GetItem(ItemType type, bool bCreateNew, int idRepository, bool bAllowContinue, out bool bSaveContinue)
		{
			IRepositoryItem parentItem = null;
			IRepositoryItem item = createItem(type, bCreateNew, true, idRepository, bAllowContinue,
												 ref parentItem, out bSaveContinue);
			if ( bCreateNew ) addItem(item);
			return item;
		}
		public IRepositoryItem GetItem(ItemType type, bool bCreateNew, int idRepository, bool bShowInputDialog, bool bAllowContinue, out bool bSaveContinue)
		{
			IRepositoryItem parentItem = null;
			IRepositoryItem item = createItem(type, bCreateNew, bShowInputDialog, idRepository,
											  bAllowContinue, ref parentItem, out bSaveContinue);
			if ( bCreateNew ) addItem(item);
			return item;
		}
		public IRepositoryItem GetItem(ItemType type, int id, bool bPreLoad)
		{
			return GetItem(type, id, "", bPreLoad);
		}

		public IRepositoryItem GetItem(ItemType type, int id, string name, bool bPreLoad)
		{
			IRepositoryItem item = null;
			RepositoryItemKey key = new RepositoryItemKey(type, id);
			if ( _items.ContainsKey(key) ) {
				item = _items[key];
				if ( bPreLoad )
					item.Reload();
			} else {
				item = this.GetItem(type, false, 0);
				item.SetIdAndName(id, name);
				if ( bPreLoad ) {
					if ( !item.Load(id) )
						return null;
				}
				addItem(item);
			}
			if ( item is RepositoryItemBaseEx && ( (RepositoryItemBaseEx)item ).IsDeleted )
				return null;

			return item;
		}
		public IRepositoryItem GetItem(ItemType type, DataRow row)
		{
			RepositoryItemKey key;
			IRepositoryItem item = this.GetItem(type, false, 0);
			DataRowItemAbstract dritem = item as DataRowItemAbstract;
			if ( row == null )
				item.CreateNew();
			else if ( dritem != null )
				dritem.row = row;
			key = new RepositoryItemKey(item);
			if ( !_items.ContainsKey(key) )
				addItem(item);
			else
				item = _items[key];
			return item;
		}

		public T GetItem<T>(int id)
			where T : class, IRepositoryItem
		{
			if ( id <= 0 ) return null;
			ItemType type = ItemType.Undefined;
			object[] attribs = typeof(T).GetCustomAttributes(typeof(RepositoryItemAttribute), false);
			foreach ( object attrib in attribs ) {
				RepositoryItemAttribute ria = attrib as RepositoryItemAttribute;
				if ( ria != null ) {
					type = ria.ItemType;
					break;
				}
			}
			if ( type == ItemType.Undefined ) {
				throw new Exception(
					string.Format("The type '{0}' does not include a valid RepositoryItemAttribute.",
								  typeof(T).FullName));
			}
			T item = GetItem(type, id, false) as T;
			if ( item == null ) {
				IRepositoryItem baseItem = GetItem(type, id, true);
				if ( baseItem == null ) return null;
				baseItem.Load(id);
			}
			return item;
		}
		public T GetNewItem<T>()
			where T : class, IRepositoryItem
		{
			IRepositoryItem parentItem = null;
			return GetNewItem<T>(false, ref parentItem);
		}
		public T GetNewItem<T>(bool bShowInputDialog)
			where T : class, IRepositoryItem
		{
			IRepositoryItem parentItem = null;
			return GetNewItem<T>(bShowInputDialog, ref parentItem);
		}
		public T GetNewItem<T>(bool bShowInputDialog, ref IRepositoryItem parentItem)
			where T : class, IRepositoryItem
		{
			ItemType type = getItemTypeFromIRepositoryItemClass<T>();

			return GetNewItem(type, bShowInputDialog, ref parentItem) as T;
		}

		public T GetNewItem<T>(bool bShowInputDialog, ref IRepositoryItem parentItem, out bool isSaveContinue)
			where T : class, IRepositoryItem
		{
			ItemType type = getItemTypeFromIRepositoryItemClass<T>();

			return GetNewItem(type, bShowInputDialog, ref parentItem, out isSaveContinue) as T;
		}

		internal void RemoveFromCache(IRepositoryItem item)
		{
			if ( item == null ) return;

			item.ItemChanging -= new OpenComposite.EII.Services.RepositoryChangingEventHandler(item_ItemChanging);
			item.ItemChanged -= new OpenComposite.EII.Services.RepositoryChangedEventHandler(item_ItemChanged);
			item.ItemDeleting -= new OpenComposite.EII.Services.RepositoryEventHandler(item_ItemDeleting);
			item.ItemDeleted -= new OpenComposite.EII.Services.RepositoryEventHandler(item_ItemDeleted);

			RepositoryItemKey key = new RepositoryItemKey(item);
			if ( _items.ContainsKey(key) ) {
				_items.Remove(key);
			}
		}

		#region Private Members

		#region Variables
		private Dictionary<RepositoryItemKey, IRepositoryItem> _items;
		#endregion

		#region Methods
		private void addItem(IRepositoryItem item)
		{
			if ( item == null ) return;

			RepositoryItemKey key = new RepositoryItemKey(item);
			if ( !_items.ContainsKey(key) ) {
				_items.Add(key, item);
				item.ItemChanging += new OpenComposite.EII.Services.RepositoryChangingEventHandler(item_ItemChanging);
				item.ItemChanged += new OpenComposite.EII.Services.RepositoryChangedEventHandler(item_ItemChanged);
				item.ItemDeleting += new OpenComposite.EII.Services.RepositoryEventHandler(item_ItemDeleting);
				item.ItemDeleted += new OpenComposite.EII.Services.RepositoryEventHandler(item_ItemDeleted);
			}
		}

		private IRepositoryItem loadItem(ItemType type, int id)
		{
			RepositoryItemKey key = new RepositoryItemKey(type, id);
			IRepositoryItem item = _items[key];
			if ( item == null ) {
				item = this.GetItem(type, id, false);
				//_items.Add(key, item);
			}
			return item;
		}
		private IRepositoryItem createItem(ItemType type, bool bCreateNew, bool bShowInputDlg,
			int idRepository, bool bAllowContinue, ref IRepositoryItem parentItem, out bool bSaveContinue)
		{
			bSaveContinue = false;
			IRepositoryItem item = null;

			#region Create Item
			switch ( type ) {
				case ItemType.Domain:
					item = new Domain(bCreateNew);
					break;
				//case ItemType.NounFolder:
				//case ItemType.NounCategory:
				case ItemType.Noun:
					item = new Noun(bCreateNew);
					break;
				//case ItemType.ServiceFolder:
				//    item = new Service(bCreateNew);
				//    ( (Service)item ).Type = Service.ServiceType.Category;
				//    break;
				case ItemType.Component:
					item = new Service(bCreateNew);
					( (Service)item ).Type = Service.ServiceType.Service;
					break;
				case ItemType.OrchestrationComponent:
					item = new Service(bCreateNew);
					( (Service)item ).Type = Service.ServiceType.Orchestration;
					break;
				case ItemType.RuleComponent:
					item = new Service(bCreateNew);
					( (Service)item ).Type = Service.ServiceType.Rule;
					break;
				case ItemType.SQLComponent:
					item = new Service(bCreateNew);
					( (Service)item ).Type = Service.ServiceType.SQLCommands;
					break;
				case ItemType.Selector:
					item = new Service(bCreateNew);
					( (Service)item ).Type = Service.ServiceType.Selector;
					break;
				case ItemType.HumanComponent:
					item = new Service(bCreateNew);
					( (Service)item ).Type = Service.ServiceType.HumanTask;
					break;
				case ItemType.UIComponent:
					item = new Service(bCreateNew);
					( (Service)item ).Type = Service.ServiceType.UserInterface;
					break;
				//case ItemType.OperationFolder:
				case ItemType.Operation:
					item = new Operation(bCreateNew);
					break;
				//case ItemType.BRuleFolder:
				case ItemType.BRule:
					item = new RepositoryBusinessRule(bCreateNew);
					break;
				//case ItemType.BObjectFolder:
				case ItemType.BObject:
					item = new BusinessObject(bCreateNew);
					break;
				//case ItemType.VerbFolder:
				case ItemType.Verb:
					item = new Verb(bCreateNew);
					break;
				case ItemType.Repository:
					item = new Repository.RepositoryObject(bCreateNew);
					break;
				case ItemType.SCA_Export:
				case ItemType.SCA_Import:
				case ItemType.GenericFolder:
					item = new GenericFolder(bCreateNew);
					break;
				case ItemType.BPolicy:
					item = new BusinessPolicy(bCreateNew);
					break;
				case ItemType.Composite:
				case ItemType.CompositeReference:
					item = new ServiceModule(bCreateNew);
					break;
				case ItemType.Diagram:
					item = new Diagram(bCreateNew);
					break;
				case ItemType.System:
					item = new Repository.RepositorySystem(bCreateNew);
					break;
				case ItemType.Workflow:
					item = new Repository.Workflow(bCreateNew);
					( (Repository.Workflow)item ).Type = WorkflowType.Orchestration;
					break;
				case ItemType.Business_Process:
					item = new Repository.Workflow(bCreateNew);
					( (Repository.Workflow)item ).Type = WorkflowType.Business_Process;
					break;
				case ItemType.Mashup:
					item = new Repository.Workflow(bCreateNew);
					( (Repository.Workflow)item ).Type = WorkflowType.Mashup;
					( (Repository.Workflow)item ).BuildType = WorkflowBuildType.WCF_WindowsForm;
					break;
				case ItemType.WebService:
					item = new Repository.WebService(bCreateNew);
					break;
				case ItemType.APIService:
					item = new Repository.WebService(bCreateNew);
					( (Repository.WebService)item ).Type = WebService.ServiceType.APIService;
					break;
				case ItemType.WebMethod:
					item = new Repository.WebMethod(bCreateNew);
					break;
				case ItemType.SOBA:
					item = new Repository.SOBA(bCreateNew);
					break;
				case ItemType.KPI:
					item = new KeyPerformanceIndicator(bCreateNew);
					break;
				case ItemType.KPI_Metric:
					item = new Repository.KPIMetric(bCreateNew);
					break;
				case ItemType.BUSActivity:
				case ItemType.LogicalActivity:
					item = new Repository.LogicalActivity(bCreateNew);
					break;
				case ItemType.RuleConstant:
					item = new Repository.RuleConstant(bCreateNew);
					break;
				case ItemType.HumanActivity:
					item = new Repository.HumanActivity(bCreateNew);
					break;
				case ItemType.Workflow_Method:
					item = new Repository.WorkflowMethod(_surfaceManager, bCreateNew);
					break;
				case ItemType.Workflow_Event:
					item = new Repository.WorkflowEvent(_surfaceManager, bCreateNew);
					break;
				case ItemType.Workflow_Field:
					item = new Repository.WorkflowField(_surfaceManager, bCreateNew);
					break;
				case ItemType.LogicalWebMethod:
					item = new Repository.LogicalWebMethod(_surfaceManager, bCreateNew);
					break;
				case ItemType.ExposedCapability:
				case ItemType.Capability:
					item = new Repository.Capability(_surfaceManager, bCreateNew);
					break;
				case ItemType.LogicalMethodGroup:
					item = new Repository.LogicalMethodGroup(_surfaceManager, bCreateNew);
					break;
				case ItemType.Organization:
					item = new Repository.Organization(bCreateNew);
					break;
				case ItemType.OrgUnit:
					item = new Repository.OrganizationalUnit(bCreateNew);
					break;
				case ItemType.Role:
					item = new Repository.Role(bCreateNew);
					break;
				case ItemType.User:
					item = new Repository.User(bCreateNew);
					break;
				case ItemType.Documentation:
					item = new Repository.Documentation(_surfaceManager, bCreateNew);
					break;
				case ItemType.MessageQueue:
					item = new Repository.MessageQueueEx(bCreateNew);
					break;
				default:
					break;
			}
			System.Diagnostics.Debug.Assert(item != null);
			item.InitializeServiceProvider(this._surfaceManager);
			#endregion
			#region Get Name and Description
			if ( bCreateNew && bShowInputDlg && item != null ) {
				int idDomain = -1;
				if ( parentItem != null ) {
					if ( parentItem is Domain ) {
						idDomain = parentItem.ID;
					} else if ( parentItem is RepositoryItemBaseEx ) {
						idDomain = ( (RepositoryItemBaseEx)parentItem ).DomainId;
					}
				}
				if ( !( item is Domain ) && idDomain == -1 ) {
					idDomain = Global.Status.CurrentDomainId;
				}

				IRepositoryItem parentItemNew;
				DialogResult result = item.ShowNewItemForm(
						idRepository, bAllowContinue, parentItem, ref idDomain, out parentItemNew);
				if ( result == DialogResult.Cancel ) {
					item = null;
				} else if ( result == DialogResult.Retry ) {
					bSaveContinue = true;
				}
				if ( parentItemNew != null ) {
					parentItem = parentItemNew;
				}
			}
			#endregion
			#region IF bCreateNew = true AND isRepository > 0 THEN Additional Initialization
			if ( item != null && bCreateNew && idRepository > 0 ) {
				switch ( type ) {
					case ItemType.Domain:
						if ( this.Mode == RepositoryMode.CompositeDesigner )
							initializeDomainCompositeDesigner(item, idRepository);
						else
							initializeDomainComplete(item, idRepository);
						break;
				}
			}
			#endregion

			return item;
		}
		private void initializeDomainComplete(IRepositoryItem domain, int idRepository)
		{
			string[] fnames = new string[]{
				"Vocabulary",
				"Business Objects",
				"Business Policies",
				"Business Rules",
				"Business SOBAs",
				"Business Services",
				"Business Components",
				"IT SOBAs" };
			ItemType[][] ftypes = new ItemType[][]{
				new ItemType[] { ItemType.Noun, ItemType.Verb },
				new ItemType[] { ItemType.BObject },
				new ItemType[] { ItemType.BPolicy },
				new ItemType[] { ItemType.BRule },
				new ItemType[] { ItemType.System, ItemType.Business_SCA },
				new ItemType[] { ItemType.Composite },
				new ItemType[] { ItemType.Component },
				new ItemType[] { ItemType.SOBA } };

			for ( int i = 0; i < fnames.Length; i++ ) {
				bool bSC;
				IRepositoryItem parentItem = null;
				GenericFolder folder = createItem(ItemType.GenericFolder, true, false, idRepository, false,
												  ref parentItem, out bSC) as GenericFolder;
				if ( folder != null ) {
					folder.Name = fnames[i];
					folder.ItemTypes = ftypes[i];
					folder.IsUserFolder = false;
					folder.Save();
					Global.Data.AddRepositoryHierarchy(domain, folder, idRepository);
				}
			}
		}
		private void initializeDomainCompositeDesigner(IRepositoryItem domain, int idRepository)
		{
			string[] fnames = new string[]{
				"Vocabulary",
				"Services / Capabilities",
				"Business Processes",
				"Composites",
				"Mashups",
				"Business Objects",
				"Business Process Rules",
				"Business Decision Rules",
				"Selection Rules",
				"Rule Constants",
				"Logical Methods",
				"Web Services / Web Methods",
				"Message Queues",
				"Human Activities" };
			ItemType[][] ftypes = new ItemType[][] {
				new ItemType[] { ItemType.Noun },
				new ItemType[] { ItemType.Composite },
				new ItemType[] { ItemType.Business_Process },
				new ItemType[] { ItemType.Workflow },
				new ItemType[] { ItemType.Mashup },
				new ItemType[] { ItemType.BObject },
				new ItemType[] { ItemType.BPolicy, ItemType.Route },
				new ItemType[] { ItemType.BPolicy },
				new ItemType[] { ItemType.BPolicy, ItemType.LogicalWebMethod },
				new ItemType[] { ItemType.RuleConstant },
				new ItemType[] { ItemType.LogicalWebMethod },
				new ItemType[] { ItemType.WebService },
				new ItemType[] { ItemType.MessageQueue },
				new ItemType[] { ItemType.HumanActivity } };

			for ( int i = 0; i < fnames.Length; i++ ) {
				bool bSC;
				IRepositoryItem parentItem = null;
				GenericFolder folder = createItem(ItemType.GenericFolder, true, false, idRepository, false, ref parentItem, out bSC) as GenericFolder;
				if ( folder != null ) {
					folder.Name = fnames[i];
					folder.ItemTypes = ftypes[i];
					folder.IsUserFolder = false;
					folder.DomainId = domain.ID;
					folder.Save();
					Global.Data.AddRepositoryHierarchy(domain, folder, idRepository, i);
				}
			}
		}
		#endregion

		#region Event Handlers
		private void item_ItemDeleted(object sender, OpenComposite.EII.Services.RepositoryEventArgs e)
		{
			IRepositoryItem item = e.RepositoryItem;
			_items.Remove(new RepositoryItemKey(item));

			item.ItemChanging -= new OpenComposite.EII.Services.RepositoryChangingEventHandler(item_ItemChanging);
			item.ItemChanged -= new OpenComposite.EII.Services.RepositoryChangedEventHandler(item_ItemChanged);
			item.ItemDeleting -= new OpenComposite.EII.Services.RepositoryEventHandler(item_ItemDeleting);
			item.ItemDeleted -= new OpenComposite.EII.Services.RepositoryEventHandler(item_ItemDeleted);

			OnRepositoryRemoved(item);

			if ( item is BusinessObject ) {
				//	findDockContent(item.Name,_do
				for ( int i = 0; i < _lstController.Count; i++ ) {
					IController ctrl = _lstController[i];
					if ( ctrl.RepositoryItem == item ) {
						ctrl.Close();
					}
				}
			}
		}

		private void item_ItemDeleting(object sender, OpenComposite.EII.Services.RepositoryEventArgs e)
		{
			OnRepositoryRemoving(e.RepositoryItem);
		}

		private void item_ItemChanging(object sender, OpenComposite.EII.Services.RepositoryChangingEventArgs e)
		{
			OnRepositoryChanging(e);
		}

		private void item_ItemChanged(object sender, OpenComposite.EII.Services.RepositoryChangedEventArgs e)
		{
			OnRepositoryChanged(e);
			if ( e.Member != null && e.Member.Name == "Name" && e.NewValue != null ) {
				for ( int i = 0; i < _lstController.Count; i++ ) {
					IController ctrl = _lstController[i];
					if ( ctrl.RepositoryItem == e.RepositoryItem ) {
						DesignController controller = ctrl as DesignController;
						if ( controller == null ) break;
						controller.DesignerDockContent.TabText = e.NewValue.ToString();
						controller.DesignerDockContent.Text = e.NewValue.ToString();
					}
				}
			}
		}
		#endregion

		#endregion

		#endregion

		#region Create Toolbox ToolStripButtons

		#region Private Members
		#region Variables
		#endregion
		#region Methods
		private static bool getTBInfos(ItemType typeDiagram, ItemType type, out Image image, out string name, out string tooltip)
		{
			bool bExists = false;
			image = SystemIcons.Application.ToBitmap();
			name = "";
			tooltip = "";
			switch ( type ) {
				#region Domain
				case ItemType.Domain:
					image = Resources.domain;
					( (Bitmap)image ).MakeTransparent(Color.Magenta);
					name = "Domain";
					tooltip = "Domain.";
					bExists = true;
					break;
				#endregion
				#region Noun
				//case ItemType.NounFolder:
				//case ItemType.NounCategory:
				case ItemType.Noun:
					image = Resources.png_field;
					( (Bitmap)image ).MakeTransparent(Color.Magenta);
					name = "Noun";
					tooltip = "Noun.";
					bExists = true;
					break;
				#endregion
				#region KPI Metric
				case ItemType.KPI_Metric:
					image = Resources.policy;
					name = "KPI Metric";
					tooltip = "KPIMetric.";
					bExists = true;
					break;
				#endregion
				#region Component
				//case ItemType.ServiceFolder:
				case ItemType.Component:
					//case ItemType.SCA_ServiceComponent:
					image = Resources.service;
					( (Bitmap)image ).MakeTransparent(Color.Magenta);
					if ( typeDiagram == ItemType.SOBA ) {
						name = "Component";
						tooltip = "Component.";
					} else {
						name = "Business Component";
						tooltip = "Business Component.";
					}
					bExists = true;
					break;
				#endregion
				#region Operation
				//case ItemType.OperationFolder:
				case ItemType.Operation:
					image = Resources.method;
					( (Bitmap)image ).MakeTransparent(Color.Magenta);
					name = "Operation";
					tooltip = "Operation.";
					bExists = true;
					break;
				#endregion
				#region BRule
				//case ItemType.BRuleFolder:
				case ItemType.BRule:
					image = Resources.png_brule;
					( (Bitmap)image ).MakeTransparent(Color.Magenta);
					name = "Business Rule";
					tooltip = "Business Rule.";
					bExists = true;
					break;
				#endregion
				#region And
				case ItemType.BRule_And:
				case ItemType.And:
					image = Resources.ico_and.ToBitmap();
					name = "AND";
					tooltip = "Logical AND Operator.";
					bExists = true;
					break;
				#endregion
				#region If
				case ItemType.BRule_If:
					image = Resources.if_png;
					name = "IF";
					tooltip = "IF <condition>.";
					bExists = true;
					break;
				#endregion
				#region Or
				case ItemType.BRule_Or:
				case ItemType.Or:
					image = Resources.ico_or.ToBitmap();
					name = "OR";
					tooltip = "Logical OR Operator.";
					bExists = true;
					break;
				#endregion
				#region XOr
				case ItemType.XOr:
					image = Resources.ico_xor.ToBitmap();
					name = "XOR";
					tooltip = "Logical XOR Operator.";
					bExists = true;
					break;
				#endregion
				#region Then-Else
				case ItemType.BRule_ThenElse:
					image = Resources.then_png;
					name = "THEN";
					tooltip = "THEN <action>.";
					bExists = true;
					break;
				#endregion
				#region BObject
				//case ItemType.BObjectFolder:
				case ItemType.BObject:
					image = Resources.bobject;
					( (Bitmap)image ).MakeTransparent(Color.Magenta);
					name = "Business Object";
					tooltip = "Business Object.";
					bExists = true;
					break;
				#endregion
				#region Verb
				//case ItemType.VerbFolder:
				case ItemType.Verb:
					image = Resources.verb;
					( (Bitmap)image ).MakeTransparent(Color.Magenta);
					name = "Capability";
					tooltip = "Capability.";
					bExists = true;
					break;
				#endregion
				#region Repository
				case ItemType.Repository:
					image = Resources.folder_closed;
					( (Bitmap)image ).MakeTransparent(Color.Magenta);
					name = "Repository";
					tooltip = "Repository.";
					bExists = true;
					break;
				#endregion
				#region Generic Folder
				case ItemType.GenericFolder:
					image = Resources.folder_closed;
					( (Bitmap)image ).MakeTransparent(Color.Magenta);
					name = "Container";
					tooltip = "Container.";
					bExists = true;
					break;
				#endregion
				#region BPolicy
				case ItemType.BPolicy:
					image = Resources.policy;
					( (Bitmap)image ).MakeTransparent(Color.Magenta);
					name = "Business Policy";
					tooltip = "Business Policy.";
					bExists = true;
					break;
				#endregion
				#region SCA Export
				case ItemType.SCA_Export:
					image = Resources.export;
					( (Bitmap)image ).MakeTransparent(Color.Magenta);
					name = "Service";
					tooltip = "Make Operations of a Component available to other Services. (Interface)";
					bExists = true;
					break;
				#endregion
				#region SCA Import
				case ItemType.SCA_Import:
					image = Resources.import;
					( (Bitmap)image ).MakeTransparent(Color.Magenta);
					name = "Reference";
					tooltip = "Import a Reference to an other Service into a Composite Business Service.";
					bExists = true;
					break;
				#endregion
				#region SCA StandaloneReference
				case ItemType.SCA_StandaloneReference:
					image = Resources.bmp_reference;
					( (Bitmap)image ).MakeTransparent(Color.Magenta);
					name = "Standalone Reference";
					tooltip = "Standalone Reference.";
					bExists = true;
					break;
				#endregion
				#region Composite / CompositeReference
				case ItemType.Composite:
				case ItemType.CompositeReference:
					image = Resources.png_capability;
					//( (Bitmap)image ).MakeTransparent(Color.Magenta);
					name = "Service";
					tooltip = "A Service.";
					bExists = true;
					break;
				#endregion
				#region SCA External
				case ItemType.SCA_External:
					image = SystemIcons.Information.ToBitmap();
					name = "External";
					tooltip = "External object in intra- or internet.";
					bExists = true;
					break;
				#endregion
				#region Diagram
				case ItemType.Diagram:
					image = Resources.diagram;
					( (Bitmap)image ).MakeTransparent(Color.Magenta);
					name = "Diagram";
					tooltip = "Diagram.";
					bExists = true;
					break;
				#endregion
				#region FA Domain
				case ItemType.FA_Domain:
					image = Resources.domain;
					( (Bitmap)image ).MakeTransparent(Color.Magenta);
					name = "Business Domain";
					tooltip = "Business Domain.";
					bExists = true;
					break;
				#endregion
				#region FA Service
				case ItemType.FA_Service:
					image = Resources.service;
					( (Bitmap)image ).MakeTransparent(Color.Magenta);
					name = "Business Service";
					tooltip = "Business Service.";
					bExists = true;
					break;
				#endregion
				#region ITObject
				case ItemType.ITObject:
					image = Resources.service;
					( (Bitmap)image ).MakeTransparent(Color.Magenta);
					name = "IT Application";
					tooltip = "IT Application.";
					bExists = true;
					break;
				#endregion
				#region BObject Icon
				case ItemType.BObjectIcon:
					image = Resources.bobject;
					( (Bitmap)image ).MakeTransparent(Color.Magenta);
					name = "Business Object Icon";
					tooltip = "Business Object Process Symbol.";
					bExists = true;
					break;
				#endregion
				#region Activity
				case ItemType.Activity:
					image = Resources.ico_delete_16x.ToBitmap();
					name = "Activity";
					tooltip = "Business Process Activity Symbol.";
					bExists = true;
					break;
				#endregion
				#region Label
				case ItemType.Label:
					image = Resources.label;
					name = "Label";
					tooltip = "Provides descriptive text for the designer.";
					bExists = true;
					break;
				#endregion
				#region Selector
				case ItemType.Selector:
					image = Resources.ico_selector.ToBitmap();
					name = "Selector";
					tooltip = "Selector.";
					bExists = true;
					break;
				#endregion
				#region System
				case ItemType.System:
					image = Resources.ico_system.ToBitmap();
					name = "System";
					tooltip = "SOBA System.";
					bExists = true;
					break;
				#endregion
				#region SOBA
				case ItemType.SOBA:
					image = Resources.ico_system.ToBitmap();
					name = "SOBA";
					tooltip = "Service Oriented Business Application.";
					bExists = true;
					break;
				#endregion
				#region Mapping
				case ItemType.Mapping:
					image = Resources.bmp_mapping;
					( (Bitmap)image ).MakeTransparent(Color.Magenta);
					name = "Mapping";
					tooltip = "Mapping.";
					bExists = true;
					break;
				#endregion
				#region Orchestration Component
				case ItemType.OrchestrationComponent:
					image = Resources.png_bprocess;
					name = "Orchestration Component";
					tooltip = "Orchestration Component.";
					bExists = true;
					break;
				#endregion
				#region Rule Component
				case ItemType.RuleComponent:
					image = Resources.ico_brule.ToBitmap();
					name = "Business Rule Component";
					tooltip = "Business Rule Component.";
					bExists = true;
					break;
				#endregion
				#region Human Component
				case ItemType.HumanComponent:
					image = Resources.png_user;
					name = "Human Task";
					tooltip = "Human Task Component.";
					bExists = true;
					break;
				#endregion
				#region UI Component
				case ItemType.UIComponent:
					image = Resources.png_form;
					name = "UI Component";
					tooltip = "User Interfacce Component.";
					bExists = true;
					break;
				#endregion
				#region SQL Component
				case ItemType.SQLComponent:
					image = Resources.ico_db.ToBitmap();
					name = "SQL Component";
					tooltip = "SQL Query Component.";
					bExists = true;
					break;
				#endregion
				#region While
				case ItemType.While:
					image = Resources.ico_process.ToBitmap();
					name = "While";
					tooltip = "While Loop.";
					bExists = true;
					break;
				#endregion
				#region BUS Activity
				case ItemType.BUSActivity:
					image = Resources.delete;
					name = "BUS Activity";
					tooltip = "Logical Activity in the BUS View.";
					bExists = true;
					break;
				#endregion
				#region Workflow
				case ItemType.Workflow:
					image = Resources.png_orchestration;
					name = "Composite";
					tooltip = "A composite with an orchestration.";
					bExists = true;
					break;
				#endregion
				#region Organisation
				case ItemType.Organization:
					image = Resources.png_org;
					name = "Enterprise";
					tooltip = "An Organisation.";
					bExists = true;
					break;
				#endregion
				#region OrgUnit
				case ItemType.OrgUnit:
					image = Resources.png_org_unit;
					name = "Org Unit";
					tooltip = "An Organisational Unit.";
					bExists = true;
					break;
				#endregion
				#region Role
				case ItemType.Role:
					image = Resources.png_users;
					name = "Role";
					tooltip = "A Role.";
					bExists = true;
					break;
				#endregion
				#region User
				case ItemType.User:
					image = Resources.png_user;
					name = "User";
					tooltip = "An User.";
					bExists = true;
					break;
				#endregion
				#region DEFAULT
				default:
					break;
				#endregion
			}
			return bExists;
		}
		#endregion
		#endregion

		public static bool GetToolboxInfos(ItemType typeDiagram, ItemType type, out Image image, out string name, out string tooltip)
		{
			return getTBInfos(typeDiagram, type, out image, out name, out tooltip);
		}
		public ToolStripButton CreateToolStripButton(ItemType type)
		{
			return CreateToolStripButton(ItemType.Undefined, type);
		}
		public ToolStripButton CreateToolStripButton(ItemType typeDiagram, ItemType type)
		{
			Image image;
			string name, tooltip;
			ToolStripButton tsbtn = null;
			if ( getTBInfos(typeDiagram, type, out image, out name, out tooltip) ) {
				tsbtn = new ToolStripButton();
				tsbtn.AutoSize = true;
				tsbtn.Name = name;
				tsbtn.Text = name;
				tsbtn.ToolTipText = tooltip;
				tsbtn.Image = image;
				tsbtn.ImageTransparentColor = Color.Magenta;
				tsbtn.DisplayStyle = ToolStripItemDisplayStyle.ImageAndText;
				tsbtn.TextImageRelation = TextImageRelation.ImageBeforeText;
				tsbtn.TextAlign = ContentAlignment.MiddleLeft;
				tsbtn.ImageAlign = ContentAlignment.MiddleLeft;
				tsbtn.Tag = type;
			} else {
				tsbtn = new ToolStripButton();
				tsbtn.AutoSize = true;
				tsbtn.Name = type.ToString();
				tsbtn.Text = "Unknown Type";
				tsbtn.ToolTipText = "Unknown Type: " + type.ToString();
				tsbtn.Image = Resources.ico_delete_16x.ToBitmap();
				tsbtn.ImageTransparentColor = Color.Magenta;
				tsbtn.DisplayStyle = ToolStripItemDisplayStyle.ImageAndText;
				tsbtn.TextImageRelation = TextImageRelation.ImageBeforeText;
				tsbtn.TextAlign = ContentAlignment.MiddleLeft;
				tsbtn.ImageAlign = ContentAlignment.MiddleLeft;
				tsbtn.Tag = type;
			}
			return tsbtn;
		}

		#endregion

		#region Create DesignerControls

		#region Private Members
		#region Variables
		#endregion
		#region Methods
		private DesignerControl createDesignerControlByType(ItemType typeDiagram, ItemType type)
		{
			DesignerControl dctrl = null;
			Type t = getDesignerControlTypeByItemType(typeDiagram, type);
			if ( t != null ) {
				System.Reflection.ConstructorInfo ctor = t.GetConstructor(Type.EmptyTypes);
				dctrl = ctor.Invoke(new object[0]) as DesignerControl;
				dctrl.InitializeNew(this);
				// do additional initialization
				if ( dctrl is ServiceModuleSymbol ) {
					if ( typeDiagram == ItemType.SOBA || typeDiagram == ItemType.Composite )
						( (ServiceModuleSymbol)dctrl ).IsCollapsed = false;
				}
			}
			return dctrl;
		}
		private Type getDesignerControlTypeByItemType(ItemType typeDiagram, ItemType itemtype)
		{
			Type type = null;
			switch ( itemtype ) {
				case ItemType.Domain:
					type = typeof(DomainSymbol);
					break;
				//case ItemType.NounFolder:
				//case ItemType.NounCategory:
				case ItemType.Noun:
					break;
				//case ItemType.ServiceFolder:
				case ItemType.Component:
					//case ItemType.SCA_ServiceComponent:
					if ( typeDiagram == ItemType.SOBA )
						type = typeof(ServiceModuleSymbol);
					else
						type = typeof(ServiceComponentSymbol);
					break;
				//case ItemType.OperationFolder:
				case ItemType.Operation:
					break;
				//case ItemType.BRuleFolder:
				case ItemType.BRule:
					type = typeof(Designer.BRules.BusinessRuleSymbol);
					break;
				case ItemType.BRule_And:
				case ItemType.And:
					type = typeof(ANDSymbol);
					break;
				case ItemType.BRule_If:
					type = typeof(Designer.BRules.IFSymbol);
					break;
				case ItemType.BRule_Or:
				case ItemType.Or:
					type = typeof(ORSymbol);
					break;
				case ItemType.BRule_ThenElse:
					type = typeof(Designer.BRules.THENResultSymbol);
					//type = typeof(Designer.BRules.THENELSESymbol);
					break;
				//case ItemType.BObjectFolder:
				case ItemType.BObject:
					type = typeof(BusinessObjectSymbol);
					break;
				//case ItemType.VerbFolder:
				case ItemType.Verb:
					type = typeof(VerbSymbol);
					break;
				case ItemType.Repository:
					break;
				case ItemType.GenericFolder:
					break;
				case ItemType.BPolicy:
					type = typeof(PolicyComponentSymbol);
					break;
				case ItemType.SCA_Export:
					type = typeof(InterfaceSymbol);
					break;
				case ItemType.SCA_Import:
					type = typeof(ReferenceSymbol);
					break;
				case ItemType.SCA_StandaloneReference:
					type = typeof(StandaloneReferenceSymbol);
					break;
				case ItemType.SCA_External:
					type = typeof(ExternalSymbol);
					break;
				case ItemType.FA_Domain:
					type = typeof(DomainSymbol);
					break;
				case ItemType.FA_Service:
					type = typeof(Designer.BusinessServices.BusinessServiceSymbol);
					break;
				case ItemType.ITObject:
					type = typeof(Designer.ITStructure.ITObjectSymbol);
					break;
				case ItemType.BObjectIcon:
					type = typeof(Designer.BObjects.BOProcessSymbol);
					break;
				case ItemType.Activity:
					type = typeof(Designer.BusinessProcess.ActivitySymbol);
					break;
				case ItemType.Label:
					type = typeof(OpenComposite.Base.Designer.Label);
					break;
				case ItemType.XOr:
					type = typeof(XORSymbol);
					break;
				case ItemType.Selector:
					type = typeof(Designer.Selector.SelectorSymbol);
					break;
				case ItemType.System:
					type = typeof(Designer.SCA.SystemSymbol);
					break;
				case ItemType.Mapping:
					type = typeof(Designer.Generic.MappingSymbol);
					break;
				case ItemType.OrchestrationComponent:
					type = typeof(Designer.SCA.OrchestrationComponentSymbol);
					break;
				case ItemType.RuleComponent:
					type = typeof(Designer.SCA.RuleComponentSymbol);
					break;
				case ItemType.HumanComponent:
					type = typeof(Designer.SCA.HumanComponentSymbol);
					break;
				case ItemType.UIComponent:
					type = typeof(Designer.SCA.UIComponentSymbol);
					break;
				case ItemType.SQLComponent:
					type = typeof(Designer.SCA.SQLComponentSymbol);
					break;
				case ItemType.BProcess_Start:
					type = typeof(Designer.BusinessProcess.StartSymbol);
					break;
				case ItemType.BProcess_End:
					type = typeof(Designer.BusinessProcess.EndSymbol);
					break;
				case ItemType.While:
					type = typeof(Designer.BusinessProcess.WhileSymbol);
					break;
				case ItemType.Diagram:
					//if ( typeDiagram == ItemType.SOBA )
					//    type = typeof(ServiceModuleSymbol);
					break;
				case ItemType.SOBA:
					type = typeof(Designer.SCA.SOBASymbol);
					break;
				case ItemType.CompositeReference:
					type = typeof(Designer.SCA.CompositeReferenceSymbol);
					break;
				case ItemType.LogicalActivity:
					type = typeof(CapabilitySymbol);
					break;
				case ItemType.BUS:
					type = typeof(BUSSymbol);
					break;
				case ItemType.BUSActivity:
					type = typeof(BUSActivitySymbol);
					break;
				case ItemType.BUSDocument:
					type = typeof(BUSDocumentSymbol);
					break;
				case ItemType.BUSVariables:
					type = typeof(BUSVariablesSymbol);
					break;
				case ItemType.Composite:
					if ( typeDiagram == ItemType.Workflow ) {
						type = typeof(ServiceModuleSymbol);
					} else {
						type = typeof(CompositeSymbol);
					}
					break;
				case ItemType.Capability:
					if ( typeDiagram == ItemType.ExposedCapability ) {
						type = typeof(ExposedCapabilitySymbol);
					} else {
						type = typeof(CapabilitySymbol);
					}
					break;
				case ItemType.ExposedCapability:
					type = typeof(ExposedCapabilitySymbol);
					break;
				case ItemType.Workflow:
					type = typeof(WorkflowReferenceSymbol);
					break;
				//case ItemType.Organisation:
				//    type = typeof(OrgSymbol);
				//    break;
				case ItemType.OrgUnit:
					type = typeof(OrgUnitSymbol);
					break;
				case ItemType.Role:
					type = typeof(RoleSymbol);
					break;
				case ItemType.User:
					type = typeof(UserSymbol);
					break;
				default:
					break;
			}
			return type;
		}
		#endregion
		#endregion

		public Type GetDesignerControlType(ItemType itemtype)
		{
			return getDesignerControlTypeByItemType(ItemType.Undefined, itemtype);
		}
		public DesignerControl CreateDesignerControl(ItemType type)
		{
			return CreateDesignerControl(type, true);
		}
		public DesignerControl CreateDesignerControl(ItemType type, bool bShowInputDialog)
		{
			DesignerControl dctrl = createDesignerControlByType(ItemType.Undefined, type);
			if ( dctrl != null && dctrl is IRepositoryItemSymbol ) {
				bool bSC;
				IRepositoryItem item = this.GetItem(type, true, Global.Status.CurrentRepositoryId,
													bShowInputDialog, false, out bSC);
				if ( item != null ) {

					( (IRepositoryItemSymbol)dctrl ).RepositoryItem = item;

				} else {
					dctrl = null;
				}
			}
			return dctrl;
		}
		public DesignerControl CreateDesignerControl(ItemType type, bool bShowInputDialog,
													 IRepositoryItem parentItem)
		{
			DesignerControl dctrl = createDesignerControlByType(ItemType.Undefined, type);
			if ( dctrl != null && dctrl is IRepositoryItemSymbol ) {
				bool bSC;
				IRepositoryItem item;
				if ( parentItem == null ) {
					item = this.GetItem(type, true, 0, bShowInputDialog, false, out bSC);
				} else {
					item = this.GetNewItem(type, bShowInputDialog, ref parentItem);
				}
				if ( item != null )
					( (IRepositoryItemSymbol)dctrl ).RepositoryItem = item;
				else
					dctrl = null;

			}
			return dctrl;
		}
		public DesignerControl CreateDesignerControl(RepositoryItemBase item)
		{
			ItemType type = item.RepositoryItemType;
			RepositoryItemDesigner ridesigner = RepositoryService.GetDesigner(item) as RepositoryItemDesigner;
			if ( ridesigner != null ) {
				type = ridesigner.GetDesignerControlItemType();
			}
			DesignerControl dctrl = createDesignerControlByType(ItemType.Undefined, type);
			if ( dctrl != null && dctrl is IRepositoryItemSymbol ) {
				( (IRepositoryItemSymbol)dctrl ).RepositoryItem = item;
			}
			return dctrl;
		}
		public DesignerControl CreateDesignerControl(ItemType typeDiagram, RepositoryItemBase item)
		{
			ItemType type = item.RepositoryItemType;
			#region get component type / composite diagram type
			if ( item is Repository.Service ) {
				switch ( ( (Repository.Service)item ).Type ) {
					case Service.ServiceType.Service:
						type = ItemType.Component;
						break;
					case Service.ServiceType.Orchestration:
						type = ItemType.OrchestrationComponent;
						break;
					case Service.ServiceType.HumanTask:
						type = ItemType.HumanComponent;
						break;
					case Service.ServiceType.UserInterface:
						type = ItemType.UIComponent;
						break;
					case Service.ServiceType.SQLCommands:
						type = ItemType.SQLComponent;
						break;
					case Service.ServiceType.Selector:
						type = ItemType.Selector;
						break;
					case Service.ServiceType.Rule:
						type = ItemType.RuleComponent;
						break;
				}
			} else if ( item is Repository.ServiceModule ) {
				Repository.ServiceModule svcmod = (Repository.ServiceModule)item;
				if ( svcmod.WorkflowID > 0 ) {
					typeDiagram = ItemType.Workflow;
				}
			}
			#endregion
			DesignerControl dctrl = createDesignerControlByType(typeDiagram, type);
			if ( dctrl != null && dctrl is IRepositoryItemSymbol ) {
				( (IRepositoryItemSymbol)dctrl ).RepositoryItem = item;
			}
			return dctrl;
		}

		public DesignerControl CreateReferenceDesignerControl(RepositoryItemBase item)
		{
			DesignerControl dctrl = null;
			ItemType type = ItemType.Undefined;
			switch ( item.RepositoryItemType ) {
				case ItemType.Composite:
					type = ItemType.CompositeReference;
					break;
			}
			if ( type != ItemType.Undefined ) {
				dctrl = createDesignerControlByType(ItemType.Undefined, type);
				if ( dctrl != null && dctrl is IRepositoryItemSymbol ) {
					( (IRepositoryItemSymbol)dctrl ).RepositoryItem = item;
				}
			}
			return dctrl;
		}
		#endregion

		#region Create Property Dialogs

		#region Private Members
		#region Variables
		#endregion
		#region Methods
		private void initPropertyDialogs()
		{
		}
		#endregion
		#endregion

		public Form CreatePropertyDialog(ItemType type)
		{
			return null;
		}

		#endregion

		#region Create Repository Item UIs

		#region Private Members
		#region Variables
		private UCDomain _ucdomain = null;
		private UCService _ucservice = null;
		private UCNoun _ucnoun = null;
		private UCBObject _ucbobject = null;
		private UCVerb _ucverb = null;
		private UCFolder _ucfolder = null;
		private UCBPolicy _ucbpolicy = null;
		private UCServiceModule _ucscvmodule = null;
		private UCDiagram _ucdiagram = null;
		private UCRepository _ucrepository = null;
		private UCSystem _ucsystem = null;
		private UCWebService _ucwebservice = null;
		private UCWebMethod _ucwebmethod = null;
		private UCWorkflow _ucworkflow = null;
		private UCSOBA _ucsoba = null;
		private UCRuleConstant _ucruleconstant = null;
		private UCHumanActivity _uchumanactivity = null;
		private UCLogicalWebMethod _uclogicalwebmethod = null;
		private UCCapability _uccapability = null;
		private UCLogicalMethodGroup _uclogicalmethodgroup = null;
		private UCRepositoryBusinessRuleUI _ucbusinessrule = null;
		private UCDocumentation _ucdocumentation = null;
		private UCKPI _uckpi = null;
		private UCOrganisationDesigner _ucOrg = null;
		private UCMessageQueue _ucMsmq = null;
		#endregion
		#region Methods
		private void initRepositoryItemUIs()
		{
			//initBObjectUI();
			//initDiagramUI();
			//initDomainUI();
			//initFolderUI();
			//initNounUI();
			//initOperationUI();
			//initPolicyUI();
			//initServiceModuleUI();
			//initServiceUI();
			//initVerbUI();
			//initRepositoryUI();
			//initSystemUI();
			//initWebServiceUI();
			//initWebMethodUI();
			//initWorkflowUI();
			//initSOBAUI();
			//initRuleConstantUI();
		}
		private void initDomainUI()
		{
			//
			// _ucdomain
			//
			_ucdomain = new UCDomain(_surfaceManager);
			_ucdomain.Location = new Point(0, 0);
			_ucdomain.Visible = false;
			_ucdomain.Dock = DockStyle.Fill;
		}
		private void initServiceUI()
		{
			//
			// _ucservice
			//
			_ucservice = new UCService(_surfaceManager);
			_ucservice.Location = new Point(0, 0);
			_ucservice.Visible = false;
			_ucservice.Dock = DockStyle.Fill;
		}
		private void initNounUI()
		{
			//
			// _ucnoun
			//
			_ucnoun = new UCNoun(_surfaceManager);
			_ucnoun.Location = new Point(0, 0);
			_ucnoun.Visible = false;
			_ucnoun.Dock = DockStyle.Fill;
		}
		private void initBObjectUI()
		{
			//
			// _ucbobject
			//
			_ucbobject = new UCBObject(_surfaceManager);
			_ucbobject.Location = new Point(0, 0);
			_ucbobject.Visible = false;
			_ucbobject.Dock = DockStyle.Fill;
		}
		private void initVerbUI()
		{
			//
			// _ucverb
			//
			_ucverb = new UCVerb(_surfaceManager);
			_ucverb.Location = new Point(0, 0);
			_ucverb.Visible = false;
			_ucverb.Dock = DockStyle.Fill;
		}
		private void initFolderUI()
		{
			//
			// _ucfolder
			//
			_ucfolder = new UCFolder(_surfaceManager);
			_ucfolder.Location = new Point(0, 0);
			_ucfolder.Visible = false;
			_ucfolder.Dock = DockStyle.Fill;
		}
		private void initPolicyUI()
		{
			//
			// _ucbpolicy
			//
			_ucbpolicy = new UCBPolicy(_surfaceManager);
			_ucbpolicy.Location = new Point(0, 0);
			_ucbpolicy.Visible = false;
			_ucbpolicy.Dock = DockStyle.Fill;
		}
		private void initServiceModuleUI()
		{
			//
			// _ucscvmodule
			//
			_ucscvmodule = new UCServiceModule(_surfaceManager);
			_ucscvmodule.Location = new Point(0, 0);
			_ucscvmodule.Visible = false;
			_ucscvmodule.Dock = DockStyle.Fill;
		}
		private void initDiagramUI()
		{
			//
			// _ucdiagram
			//
			_ucdiagram = new UCDiagram(_surfaceManager);
			_ucdiagram.Location = new Point(0, 0);
			_ucdiagram.Visible = false;
			_ucdiagram.Dock = DockStyle.Fill;
		}
		private void initRepositoryUI()
		{
			//
			// _ucrepository
			//
			_ucrepository = new UCRepository(_surfaceManager);
			_ucrepository.Location = new Point(0, 0);
			_ucrepository.Visible = false;
			_ucrepository.Dock = DockStyle.Fill;
		}
		private void initSystemUI()
		{
			//
			// _ucsystem
			//
			_ucsystem = new UCSystem(_surfaceManager);
			_ucsystem.Location = new Point(0, 0);
			_ucsystem.Visible = false;
			_ucsystem.Dock = DockStyle.Fill;
		}
		private void initWebServiceUI()
		{
			//
			// _ucwebservice
			//
			_ucwebservice = new UCWebService(_surfaceManager);
			_ucwebservice.Location = new Point(0, 0);
			_ucwebservice.Visible = false;
			_ucwebservice.Dock = DockStyle.Fill;
		}
		private void initWebMethodUI()
		{
			//
			// _ucwebmethod
			//
			_ucwebmethod = new UCWebMethod(_surfaceManager);
			_ucwebmethod.Location = new Point(0, 0);
			_ucwebmethod.Visible = false;
			_ucwebmethod.Dock = DockStyle.Fill;
		}
		private void initWorkflowUI()
		{
			//
			// _ucworkflow
			//
			_ucworkflow = new UCWorkflow(_surfaceManager);
			_ucworkflow.Location = new Point(0, 0);
			_ucworkflow.Visible = false;
			_ucworkflow.Dock = DockStyle.Fill;
		}
		private void initSOBAUI()
		{
			//
			// _ucsoba
			//
			_ucsoba = new UCSOBA(_surfaceManager);
			_ucsoba.Location = new Point(0, 0);
			_ucsoba.Visible = false;
			_ucsoba.Dock = DockStyle.Fill;
		}
		private void initRuleConstantUI()
		{
			//
			// _ucruleconstant
			//
			_ucruleconstant = new UCRuleConstant(_surfaceManager);
			_ucruleconstant.Location = new Point(0, 0);
			_ucruleconstant.Visible = false;
			_ucruleconstant.Dock = DockStyle.Fill;
		}
		private void initHumanActivityUI()
		{
			//
			// _uchumanactivity
			//
			_uchumanactivity = new UCHumanActivity(_surfaceManager);
			_uchumanactivity.Location = new Point(0, 0);
			_uchumanactivity.Visible = false;
			_uchumanactivity.Dock = DockStyle.Fill;
		}
		private void initLogicalWebMethodUI()
		{
			//
			// _uclogicalwebmethod
			//
			_uclogicalwebmethod = new UCLogicalWebMethod(_surfaceManager);
			_uclogicalwebmethod.Location = new Point(0, 0);
			_uclogicalwebmethod.Visible = false;
			_uclogicalwebmethod.Dock = DockStyle.Fill;
		}
		private void initCapabilityUI()
		{
			//
			// _uccapability
			//
			_uccapability = new UCCapability(_surfaceManager);
			_uccapability.Location = new Point(0, 0);
			_uccapability.Visible = false;
			_uccapability.Dock = DockStyle.Fill;
		}
		private void initLogicalMethodGroupUI()
		{
			//
			// _uclogicalmethodgroup
			//
			_uclogicalmethodgroup = new UCLogicalMethodGroup(_surfaceManager);
			_uclogicalmethodgroup.Location = new Point(0, 0);
			_uclogicalmethodgroup.Visible = false;
			_uclogicalmethodgroup.Dock = DockStyle.Fill;
		}
		private void initBusinessRuleUI()
		{
			//
			// _ucbusinessrule
			//
			_ucbusinessrule = new UCRepositoryBusinessRuleUI(_surfaceManager);
			_ucbusinessrule.Location = new Point(0, 0);
			_ucbusinessrule.Visible = false;
			_ucbusinessrule.Dock = DockStyle.Fill;
		}
		private void initDocumentationUI()
		{
			//
			// _ucdocumentation
			//
			try {
				_ucdocumentation = new UCDocumentation(_surfaceManager);
				_ucdocumentation.Location = new Point(0, 0);
				_ucdocumentation.Visible = false;
				_ucdocumentation.Dock = DockStyle.Fill;
			} catch ( System.Runtime.InteropServices.COMException comex ) {
				Trace.WriteLine(comex.Message);
				MessageBox.Show("Could not show the documentation. Please install Adobe Reader.",
								"Show Documentation", MessageBoxButtons.OK, MessageBoxIcon.Error);
			}
		}
		private void initKPIUI()
		{
			//
			// _uckpi
			//
			_uckpi = new UCKPI(_surfaceManager);
			_uckpi.Location = new Point(0, 0);
			_uckpi.Visible = false;
			_uckpi.Dock = DockStyle.Fill;

		}
		private void initOrganisationUI()
		{
			//
			// _ucOrg
			//
			_ucOrg = new UCOrganisationDesigner(_surfaceManager);
			_ucOrg.Location = new Point(0, 0);
			_ucOrg.Visible = false;
			_ucOrg.Dock = DockStyle.Fill;
		}
		private void initMessageQueueUI()
		{
			// 
			// _ucMsmq
			// 
			_ucMsmq = new UCMessageQueue(_surfaceManager);
			_ucMsmq.Location = new Point(0, 0);
			_ucMsmq.Visible = false;
			_ucMsmq.Dock = DockStyle.Fill;
		}
		#endregion
		#endregion

		/// <summary>
		/// Creates a RepositoryItemUI for a new RepositoryItemBase object of ItemType type.
		/// </summary>
		/// <param name="type">ItemType of the new RepositoryItemBase object.</param>
		/// <returns>A RepositoryItemUI.</returns>
		public RepositoryItemUI CreateRepositoryItemUI(ItemType type)
		{
			switch ( type ) {
				case ItemType.Domain:
					if ( _ucdomain == null || _ucdomain.IsDisposed )
						initDomainUI();
					return _ucdomain;
				//case ItemType.NounCategory:
				case ItemType.Noun:
					if ( _ucnoun == null || _ucnoun.IsDisposed )
						initNounUI();
					return _ucnoun;
				case ItemType.Component:
					if ( _ucservice == null || _ucservice.IsDisposed )
						initServiceUI();
					return _ucservice;
				case ItemType.BRule:
					if ( _ucbusinessrule == null || _ucbusinessrule.IsDisposed )
						initBusinessRuleUI();
					return _ucbusinessrule;
				case ItemType.BObject:
					if ( _ucbobject == null || _ucbobject.IsDisposed )
						initBObjectUI();
					return _ucbobject;
				case ItemType.Verb:
					if ( _ucverb == null || _ucverb.IsDisposed )
						initVerbUI();
					return _ucverb;
				case ItemType.GenericFolder:
					if ( _ucfolder == null || _ucfolder.IsDisposed )
						initFolderUI();
					return _ucfolder;
				case ItemType.BPolicy:
					if ( _ucbpolicy == null || _ucbpolicy.IsDisposed )
						initPolicyUI();
					return _ucbpolicy;
				case ItemType.Composite:
					if ( _ucscvmodule == null || _ucscvmodule.IsDisposed )
						initServiceModuleUI();
					return _ucscvmodule;
				case ItemType.Diagram:
					if ( _ucdiagram == null || _ucdiagram.IsDisposed )
						initDiagramUI();
					return _ucdiagram;
				case ItemType.Repository:
					if ( _ucrepository == null || _ucrepository.IsDisposed )
						initRepositoryUI();
					return _ucrepository;
				case ItemType.System:
					if ( _ucsystem == null || _ucsystem.IsDisposed )
						initSystemUI();
					return _ucsystem;
				case ItemType.WebService:
					if ( _ucwebservice == null || _ucwebservice.IsDisposed )
						initWebServiceUI();
					return _ucwebservice;
				case ItemType.WebMethod:
					if ( _ucwebmethod == null || _ucwebmethod.IsDisposed )
						initWebMethodUI();
					return _ucwebmethod;
				case ItemType.Workflow:
					if ( _ucworkflow == null || _ucworkflow.IsDisposed )
						initWorkflowUI();
					return _ucworkflow;
				case ItemType.SOBA:
					if ( _ucsoba == null || _ucsoba.IsDisposed )
						initSOBAUI();
					return _ucsoba;
				case ItemType.RuleConstant:
					if ( _ucruleconstant == null || _ucruleconstant.IsDisposed )
						initRuleConstantUI();
					return _ucruleconstant;
				case ItemType.HumanActivity:
					if ( _uchumanactivity == null || _uchumanactivity.IsDisposed )
						initHumanActivityUI();
					return _uchumanactivity;
				case ItemType.LogicalWebMethod:
					if ( _uclogicalwebmethod == null || _uclogicalwebmethod.IsDisposed )
						initLogicalWebMethodUI();
					return _uclogicalwebmethod;
				case ItemType.Capability:
					if ( _uccapability == null || _uccapability.IsDisposed )
						initCapabilityUI();
					return _uccapability;
				case ItemType.LogicalMethodGroup:
					if ( _uclogicalmethodgroup == null || _uclogicalmethodgroup.IsDisposed )
						initLogicalMethodGroupUI();
					return _uclogicalmethodgroup;
				case ItemType.Documentation:
					if ( _ucdocumentation == null || _ucdocumentation.IsDisposed )
						initDocumentationUI();
					return _ucdocumentation;
				case ItemType.KPI_Metric:
					if ( _uckpi == null || _uckpi.IsDisposed )
						initKPIUI();
					return _uckpi;
				case ItemType.Organization:
					if ( _ucOrg == null || _ucOrg.IsDisposed )
						initOrganisationUI();
					return _ucOrg;
				case ItemType.MessageQueue:
					if ( _ucMsmq == null || _ucMsmq.IsDisposed ) {
						initMessageQueueUI();
					}
					return _ucMsmq;
				default:
					return null;
			}
		}
		/// <summary>
		/// Creates a RepositoryItemUI for a RepositoryItemBase object.
		/// </summary>
		/// <param name="item">The RepositoryItemBase object.</param>
		/// <returns>A RepositoryItemUI.</returns>
		public RepositoryItemUI CreateRepositoryItemUI(RepositoryItemBase item)
		{
			RepositoryItemUI itemUI = this.CreateRepositoryItemUI(item.RepositoryItemType);

			if ( itemUI != null ) {
				itemUI.RepositoryItem = item;
			}

			return itemUI;
		}

		#endregion

		#region Create DesignController

		#region Private Members
		#region Variables
		List<IController> _lstController;
		#endregion

		#region Methods
		private IController initBusinessObjectDesigner(DockPanel dockPanel, IController parentController)
		{
			string designertext = "Business Object Designer";
			//string toolboxtext = "Business Object Toolbox";

			BODesignController dc = new BODesignController(_surfaceManager);
			dc.TabText = designertext;
			dc.ParentController = parentController as DesignController;

			//ToolboxDockContent tdc = findDockContent(toolboxtext, dockPanel) as ToolboxDockContent;
			//if ( tdc != null ) {
			//    dc.SetToolbox(tdc);
			//} else {
			//    dc.Toolbox.TabText = toolboxtext;
			//    dc.Toolbox.AddItem(ItemType.BObject);
			//}
			dc.ToolboxCategory = "Business Object";
			dc.Toolbox.AddItem(ItemType.BObject, "Business Object");

			dc.DesignerControlTypes.Add(typeof(BusinessObjectSymbol));
			dc.DesignerControlTypes.Add(typeof(Route));

			dc.DesignerView.DropTypes.Add(typeof(BusinessObjectSymbol));

			return dc;
		}
		private IController initSCADesigner(DockPanel dockPanel, IController parentController)
		{
			string designertext = "Business SOBA Designer";
			//string toolboxtext = "Business SOBA Toolbox";

			DesignController dc = new DesignController(_surfaceManager);
			dc.Mode = RepositoryModes.BusinessMode;
			dc.DesignerDockContent.TabText = designertext;
			dc.ParentController = parentController as DesignController;

			//ToolboxDockContent tdc = findDockContent(toolboxtext, dockPanel) as ToolboxDockContent;
			//if ( tdc != null ) {
			//    dc.SetToolbox(tdc);
			//} else {
			//    dc.Toolbox.TabText = toolboxtext;

			//dc.Toolbox.AddItem(RepositoryFactory.CreateToolStripButton(ItemType.Domain));
			dc.ToolboxCategory = "Business SOBA";
			dc.Toolbox.AddItem(ItemType.System, "Business SOBA");
			dc.Toolbox.AddItem(ItemType.Composite, "Business SOBA");
			dc.Toolbox.AddItem(ItemType.Component, "Business SOBA");
			dc.Toolbox.AddItem(ItemType.OrchestrationComponent, "Business SOBA");
			dc.Toolbox.AddItem(ItemType.RuleComponent, "Business SOBA");
			dc.Toolbox.AddItem(ItemType.HumanComponent, "Business SOBA");
			dc.Toolbox.AddItem(ItemType.UIComponent, "Business SOBA");
			dc.Toolbox.AddItem(ItemType.SQLComponent, "Business SOBA");
			dc.Toolbox.AddItem(ItemType.SCA_Export, "Business SOBA");
			dc.Toolbox.AddItem(ItemType.SCA_Import, "Business SOBA");
			dc.Toolbox.AddItem(ItemType.SCA_StandaloneReference, "Business SOBA");
			dc.Toolbox.AddItem(ItemType.SCA_External, "Business SOBA");
			dc.Toolbox.AddItem(ItemType.Selector, "Business SOBA");
			dc.Toolbox.AddItem(ItemType.Mapping, "Business SOBA");
			dc.Toolbox.AddItem(ItemType.Separator, "Business SOBA");
			dc.Toolbox.AddItem(ItemType.BPolicy, "Business SOBA");
			dc.Toolbox.AddItem(ItemType.Separator, "Business SOBA");
			//dc.Toolbox.AddItem(RepositoryFactory.CreateToolStripButton(ItemType.FA_Domain));
			dc.Toolbox.AddItem(ItemType.ITObject, "Business SOBA");
			//}
			//dc.DesignerControlTypes.Add(typeof(DomainSymbol));
			dc.DesignerControlTypes.Add(typeof(ServiceComponentSymbol));
			dc.DesignerControlTypes.Add(typeof(OrchestrationComponentSymbol));
			dc.DesignerControlTypes.Add(typeof(RuleComponentSymbol));
			dc.DesignerControlTypes.Add(typeof(HumanComponentSymbol));
			dc.DesignerControlTypes.Add(typeof(UIComponentSymbol));
			dc.DesignerControlTypes.Add(typeof(SQLComponentSymbol));
			dc.DesignerControlTypes.Add(typeof(InterfaceSymbol));
			dc.DesignerControlTypes.Add(typeof(ReferenceSymbol));
			dc.DesignerControlTypes.Add(typeof(StandaloneReferenceSymbol));
			dc.DesignerControlTypes.Add(typeof(ServiceModuleSymbol));
			dc.DesignerControlTypes.Add(typeof(ExternalSymbol));
			dc.DesignerControlTypes.Add(typeof(Route));
			dc.DesignerControlTypes.Add(typeof(Designer.ITStructure.ITObjectSymbol));
			dc.DesignerControlTypes.Add(typeof(ExternalSymbol));
			dc.DesignerControlTypes.Add(typeof(PolicyComponentSymbol));
			dc.DesignerControlTypes.Add(typeof(SystemSymbol));
			dc.DesignerControlTypes.Add(typeof(Designer.Selector.SelectorSymbol));
			dc.DesignerControlTypes.Add(typeof(MappingSymbol));

			//dc.Designer.DesignerView.DropTypes.Add(typeof(DomainSymbol));
			dc.DesignerDockContent.DesignerView.DropTypes.Add(typeof(SystemSymbol));
			dc.DesignerDockContent.DesignerView.DropTypes.Add(typeof(ServiceModuleSymbol));
			dc.DesignerDockContent.DesignerView.DropTypes.Add(typeof(ExternalSymbol));

			return dc;
		}
		private IController initSOBADesigner(DockPanel dockPanel, IController parentController)
		{
			string designertext = "SOBA Designer";
			//string toolboxtext = "SOBA Toolbox";

			DesignController dc = new DesignController(_surfaceManager);
			dc.Mode = RepositoryModes.ITMode;
			dc.DesignerDockContent.TabText = designertext;
			dc.ParentController = parentController as DesignController;

			//ToolboxDockContent tdc = findDockContent(toolboxtext, dockPanel) as ToolboxDockContent;
			//if ( tdc != null ) {
			//    dc.SetToolbox(tdc);
			//} else {
			//    dc.Toolbox.TabText = toolboxtext;

			//dc.Toolbox.AddItem(RepositoryFactory.CreateToolStripButton(ItemType.Domain));
			//dc.Toolbox.AddItem(ItemType.SOBA);
			dc.ToolboxCategory = "SOBA";
			dc.Toolbox.AddItem(ItemType.CompositeReference, "SOBA");
			dc.Toolbox.AddItem(ItemType.SOBA, ItemType.Component, "SOBA");
			dc.Toolbox.AddItem(ItemType.OrchestrationComponent, "SOBA");
			//dc.Toolbox.AddItem(ItemType.RuleComponent);
			dc.Toolbox.AddItem(ItemType.HumanComponent, "SOBA");
			dc.Toolbox.AddItem(ItemType.UIComponent, "SOBA");
			//dc.Toolbox.AddItem(ItemType.SQLComponent);
			//dc.Toolbox.AddItem(ItemType.SCA_Export);
			//dc.Toolbox.AddItem(ItemType.SCA_Import);
			//dc.Toolbox.AddItem(ItemType.SCA_StandaloneReference);
			//dc.Toolbox.AddItem(ItemType.SCA_External);
			//dc.Toolbox.AddItem(ItemType.Selector);
			//dc.Toolbox.AddItem(ItemType.Mapping);
			//dc.Toolbox.AddItem(ItemType.Separator);
			//dc.Toolbox.AddItem(ItemType.BPolicy);
			//dc.Toolbox.AddItem(ItemType.Verb);
			//dc.Toolbox.AddItem(new ToolStripSeparator());
			//dc.Toolbox.AddItem(RepositoryFactory.CreateToolStripButton(ItemType.FA_Domain));
			//dc.Toolbox.AddItem(RepositoryFactory.CreateToolStripButton(ItemType.ITObject));
			//}
			//dc.DesignerControlTypes.Add(typeof(DomainSymbol));
			dc.DesignerControlTypes.Add(typeof(ServiceComponentSymbol));
			dc.DesignerControlTypes.Add(typeof(OrchestrationComponentSymbol));
			dc.DesignerControlTypes.Add(typeof(RuleComponentSymbol));
			dc.DesignerControlTypes.Add(typeof(HumanComponentSymbol));
			dc.DesignerControlTypes.Add(typeof(UIComponentSymbol));
			dc.DesignerControlTypes.Add(typeof(SQLComponentSymbol));
			dc.DesignerControlTypes.Add(typeof(InterfaceSymbol));
			dc.DesignerControlTypes.Add(typeof(ReferenceSymbol));
			dc.DesignerControlTypes.Add(typeof(StandaloneReferenceSymbol));
			dc.DesignerControlTypes.Add(typeof(ServiceModuleSymbol));
			dc.DesignerControlTypes.Add(typeof(ExternalSymbol));
			dc.DesignerControlTypes.Add(typeof(Route));
			dc.DesignerControlTypes.Add(typeof(Designer.ITStructure.ITObjectSymbol));
			dc.DesignerControlTypes.Add(typeof(ExternalSymbol));
			dc.DesignerControlTypes.Add(typeof(PolicyComponentSymbol));
			dc.DesignerControlTypes.Add(typeof(SystemSymbol));
			dc.DesignerControlTypes.Add(typeof(Designer.Selector.SelectorSymbol));
			dc.DesignerControlTypes.Add(typeof(MappingSymbol));
			dc.DesignerControlTypes.Add(typeof(SOBASymbol));
			dc.DesignerControlTypes.Add(typeof(CapabilitySymbol));
			dc.DesignerControlTypes.Add(typeof(CompositeReferenceSymbol));

			//dc.Designer.DesignerView.DropTypes.Add(typeof(DomainSymbol));
			//dc.Designer.DesignerView.DropTypes.Add(typeof(SystemSymbol));
			//dc.Designer.DesignerView.DropTypes.Add(typeof(ServiceModuleSymbol));
			//dc.Designer.DesignerView.DropTypes.Add(typeof(ExternalSymbol));
			dc.DesignerDockContent.DesignerView.DropTypes.Add(typeof(UIComponentSymbol));

			return dc;
		}
		private IController initCompositeDesigner(DockPanel dockPanel, IController parentController)
		{
			string designertext = "Service Designer";
			//string toolboxtext = "Toolbox";

			DesignController dc = new DesignController(_surfaceManager);
			dc.Mode = RepositoryModes.GenericMode;
			dc.TabText = designertext;
			dc.ParentController = parentController as DesignController;

			//ToolboxDockContent tdc = findDockContent(toolboxtext, dockPanel) as ToolboxDockContent;
			//if ( tdc != null ) {
			//    dc.SetToolbox(tdc);
			//} else {
			//dc.Toolbox.TabText = toolboxtext;

			dc.ToolboxCategory = "Service";
			//dc.Toolbox.AddItem(ItemType.CompositeReference, "Service");
			dc.Toolbox.AddItem(ItemType.Workflow, "Service");
			//dc.Toolbox.AddItem(ItemType.Verb, "Service");
			//}
			//dc.DesignerControlTypes.Add(typeof(DomainSymbol));
			dc.DesignerControlTypes.Add(typeof(ServiceComponentSymbol));
			dc.DesignerControlTypes.Add(typeof(CompositeReferenceSymbol));
			dc.DesignerControlTypes.Add(typeof(OrchestrationComponentSymbol));
			dc.DesignerControlTypes.Add(typeof(RuleComponentSymbol));
			dc.DesignerControlTypes.Add(typeof(HumanComponentSymbol));
			dc.DesignerControlTypes.Add(typeof(UIComponentSymbol));
			dc.DesignerControlTypes.Add(typeof(SQLComponentSymbol));
			dc.DesignerControlTypes.Add(typeof(InterfaceSymbol));
			dc.DesignerControlTypes.Add(typeof(ReferenceSymbol));
			dc.DesignerControlTypes.Add(typeof(StandaloneReferenceSymbol));
			dc.DesignerControlTypes.Add(typeof(ServiceModuleSymbol));
			dc.DesignerControlTypes.Add(typeof(ExternalSymbol));
			dc.DesignerControlTypes.Add(typeof(Route));
			dc.DesignerControlTypes.Add(typeof(Designer.ITStructure.ITObjectSymbol));
			dc.DesignerControlTypes.Add(typeof(ExternalSymbol));
			dc.DesignerControlTypes.Add(typeof(PolicyComponentSymbol));
			dc.DesignerControlTypes.Add(typeof(SystemSymbol));
			dc.DesignerControlTypes.Add(typeof(Designer.Selector.SelectorSymbol));
			dc.DesignerControlTypes.Add(typeof(MappingSymbol));
			dc.DesignerControlTypes.Add(typeof(CapabilitySymbol));
			dc.DesignerControlTypes.Add(typeof(CompositeSymbol));
			dc.DesignerControlTypes.Add(typeof(ExposedCapabilitySymbol));
			dc.DesignerControlTypes.Add(typeof(VerbSymbol));
			dc.DesignerControlTypes.Add(typeof(WorkflowReferenceSymbol));

			//dc.Designer.DesignerView.DropTypes.Add(typeof(DomainSymbol));
			//dc.Designer.DesignerView.DropTypes.Add(typeof(SystemSymbol));
			//dc.Designer.DesignerView.DropTypes.Add(typeof(ServiceModuleSymbol));
			//dc.Designer.DesignerView.DropTypes.Add(typeof(ExternalSymbol));

			return dc;
		}
		private void onGenerateCompositeClick(object sender, EventArgs e)
		{
			ServiceModule svcModule = null;
			DockPanel dp = null;
			Forms.FormDeployServiceModule frm = new Forms.FormDeployServiceModule(svcModule);
			Rectangle rectFloat = new Rectangle(
				new Point(dp.Left + dp.Width / 2 - frm.Width / 2,
						  dp.Top + dp.Height / 2 - frm.Height / 2),
				frm.Size);
			rectFloat = dp.RectangleToScreen(rectFloat);
			frm.Show(dp, rectFloat);
		}
		private IController initComponentDesigner(DockPanel dockPanel, IController parentController)
		{
			string designertext = "Component Designer";

			DesignController dc = new DesignController(_surfaceManager);
			dc.Mode = RepositoryModes.GenericMode;
			dc.DesignerDockContent.TabText = designertext;
			dc.ParentController = parentController as DesignController;

			dc.SetToolbox(null);

			//dc.DesignerControlTypes.Add(typeof(DomainSymbol));
			dc.DesignerControlTypes.Add(typeof(ServiceComponentSymbol));
			dc.DesignerControlTypes.Add(typeof(OrchestrationComponentSymbol));
			dc.DesignerControlTypes.Add(typeof(RuleComponentSymbol));
			dc.DesignerControlTypes.Add(typeof(HumanComponentSymbol));
			dc.DesignerControlTypes.Add(typeof(UIComponentSymbol));
			dc.DesignerControlTypes.Add(typeof(SQLComponentSymbol));
			dc.DesignerControlTypes.Add(typeof(InterfaceSymbol));
			dc.DesignerControlTypes.Add(typeof(ReferenceSymbol));
			dc.DesignerControlTypes.Add(typeof(StandaloneReferenceSymbol));
			dc.DesignerControlTypes.Add(typeof(ServiceModuleSymbol));
			dc.DesignerControlTypes.Add(typeof(ExternalSymbol));
			dc.DesignerControlTypes.Add(typeof(Route));
			dc.DesignerControlTypes.Add(typeof(Designer.ITStructure.ITObjectSymbol));
			dc.DesignerControlTypes.Add(typeof(ExternalSymbol));
			dc.DesignerControlTypes.Add(typeof(PolicyComponentSymbol));
			dc.DesignerControlTypes.Add(typeof(SystemSymbol));
			dc.DesignerControlTypes.Add(typeof(Designer.Selector.SelectorSymbol));
			dc.DesignerControlTypes.Add(typeof(MappingSymbol));

			//dc.Designer.DesignerView.DropTypes.Add(typeof(DomainSymbol));
			//dc.Designer.DesignerView.DropTypes.Add(typeof(SystemSymbol));
			//dc.Designer.DesignerView.DropTypes.Add(typeof(ServiceModuleSymbol));
			//dc.Designer.DesignerView.DropTypes.Add(typeof(ExternalSymbol));

			return dc;
		}
		private IController initBRuleDesigner(DockPanel dockPanel, IController parentController)
		{
			string designertext = "Rule Designer";
			//string toolboxtext = "Rule Toolbox";

			DesignController dc = new Designer.BRules.BRulesDesignController(_surfaceManager);
			dc.ParentController = parentController as DesignController;
			dc.TabText = designertext;

			//ToolboxDockContent tdc = findDockContent(toolboxtext, dockPanel) as ToolboxDockContent;
			//if ( tdc != null ) {
			//    dc.SetToolbox(tdc);
			//} else {
			//    dc.Toolbox.TabText = toolboxtext;
			dc.ToolboxCategory = "Rule";
			dc.Toolbox.AddItem(ItemType.BRule, "Rule");
			dc.Toolbox.AddItem(ItemType.BRule_If, "Rule");
			dc.Toolbox.AddItem(ItemType.BRule_And, "Rule");
			dc.Toolbox.AddItem(ItemType.BRule_Or, "Rule");
			dc.Toolbox.AddItem(ItemType.BRule_ThenElse, "Rule");
			//}
			dc.DesignerControlTypes.Add(typeof(Designer.BRules.BusinessRuleSymbol));
			dc.DesignerControlTypes.Add(typeof(Designer.BRules.IFSymbol));
			dc.DesignerControlTypes.Add(typeof(Designer.BRules.THENELSESymbol));
			dc.DesignerControlTypes.Add(typeof(ANDSymbol));
			dc.DesignerControlTypes.Add(typeof(ORSymbol));
			dc.DesignerControlTypes.Add(typeof(Designer.BRules.ActionSymbol));
			dc.DesignerControlTypes.Add(typeof(Route));
			dc.DesignerControlTypes.Add(typeof(Designer.BRules.THENResultSymbol));
			dc.DesignerControlTypes.Add(typeof(Designer.BRules.ELSEResultSymbol));
			dc.DesignerControlTypes.Add(typeof(Designer.BRules.ONERRORResultSymbol));
			dc.DesignerControlTypes.Add(typeof(Designer.BRules.ParticipantRules.ELSEParticipantSymbol));
			dc.DesignerControlTypes.Add(typeof(Designer.BRules.ParticipantRules.ONERRORParticipantSymbol));
			dc.DesignerControlTypes.Add(typeof(Designer.BRules.ParticipantRules.THENParticipantSymbol));

			dc.DesignerView.DropTypes.Add(typeof(Designer.BRules.BusinessRuleSymbol));

			return dc;
		}
		private IController initBusinessDiagramDesigner(DockPanel dockPanel, IController parentController)
		{
			string designertext = "Business Service Designer";
			//string toolboxtext = "Business Service Toolbox";

			DesignController dc = new DesignController(_surfaceManager);
			dc.TabText = designertext;
			dc.ParentController = parentController as DesignController;

			//ToolboxDockContent tdc = findDockContent(toolboxtext, dockPanel) as ToolboxDockContent;
			//if ( tdc != null ) {
			//    dc.SetToolbox(tdc);
			//} else {
			//    dc.Toolbox.TabText = toolboxtext;

			dc.ToolboxCategory = "Business Service";
			dc.Toolbox.AddItem(ItemType.FA_Domain, "Business Service");
			dc.Toolbox.AddItem(ItemType.FA_Service, "Business Service");
			dc.Toolbox.AddItem(ItemType.SCA_External, "Business Service");
			dc.Toolbox.AddItem(ItemType.BObjectIcon, "Business Service");
			//}
			dc.DesignerControlTypes.Add(typeof(DomainSymbol));
			dc.DesignerControlTypes.Add(typeof(Designer.BusinessServices.BusinessServiceSymbol));
			dc.DesignerControlTypes.Add(typeof(ExternalSymbol));
			dc.DesignerControlTypes.Add(typeof(Designer.BObjects.BOProcessSymbol));
			dc.DesignerControlTypes.Add(typeof(Route));

			dc.DesignerView.DropTypes.Add(typeof(DomainSymbol));
			dc.DesignerView.DropTypes.Add(typeof(ExternalSymbol));
			dc.DesignerView.DropTypes.Add(typeof(Designer.BObjects.BOProcessSymbol));

			return dc;
		}
		private IController initITStructureDiagram(DockPanel dockPanel, IController parentController)
		{
			string designertext = "IT Structure Designer";
			//string toolboxtext = "IT Structure Toolbox";

			DesignController dc = new DesignController(_surfaceManager);
			dc.TabText = designertext;
			dc.ParentController = parentController as DesignController;

			//ToolboxDockContent tdc = findDockContent(toolboxtext, dockPanel) as ToolboxDockContent;
			//if ( tdc != null ) {
			//    dc.SetToolbox(tdc);
			//} else {
			//    dc.Toolbox.TabText = toolboxtext;

			dc.ToolboxCategory = "IT Structure";
			dc.Toolbox.AddItem(ItemType.FA_Domain, "IT Structure");
			dc.Toolbox.AddItem(ItemType.System, "IT Structure");
			dc.Toolbox.AddItem(ItemType.ITObject, "IT Structure");
			dc.Toolbox.AddItem(ItemType.SCA_External, "IT Structure");
			//}
			dc.DesignerControlTypes.Add(typeof(DomainSymbol));
			dc.DesignerControlTypes.Add(typeof(SystemSymbol));
			dc.DesignerControlTypes.Add(typeof(Designer.ITStructure.ITObjectSymbol));
			dc.DesignerControlTypes.Add(typeof(ExternalSymbol));
			dc.DesignerControlTypes.Add(typeof(Route));

			dc.DesignerView.DropTypes.Add(typeof(DomainSymbol));
			dc.DesignerView.DropTypes.Add(typeof(SystemSymbol));
			dc.DesignerView.DropTypes.Add(typeof(ExternalSymbol));

			return dc;
		}
		private IController initConnectionDiagram(DockPanel dockPanel, IController parentController)
		{
			string designertext = "SOBA Designer";
			//string toolboxtext = "SOBA Toolbox";

			DesignController dc = new DesignController(_surfaceManager);
			dc.TabText = designertext;
			dc.ParentController = parentController as DesignController;

			//ToolboxDockContent tdc = findDockContent(toolboxtext, dockPanel) as ToolboxDockContent;
			//if ( tdc != null ) {
			//    dc.SetToolbox(tdc);
			//} else {
			//    dc.Toolbox.TabText = toolboxtext;

			dc.ToolboxCategory = "Connnection";
			dc.Toolbox.AddItem(ItemType.FA_Domain, "Connnection");
			dc.Toolbox.AddItem(ItemType.FA_Service, "Connnection");
			dc.Toolbox.AddItem(ItemType.ITObject, "Connnection");
			dc.Toolbox.AddItem(ItemType.BObject, "Connnection");
			dc.Toolbox.AddItem(ItemType.Composite, "Connnection");
			dc.Toolbox.AddItem(ItemType.Component, "Connnection");
			dc.Toolbox.AddItem(ItemType.BPolicy, "Connnection");
			dc.Toolbox.AddItem(ItemType.SCA_Export, "Connnection");
			dc.Toolbox.AddItem(ItemType.SCA_Import, "Connnection");
			dc.Toolbox.AddItem(ItemType.SCA_StandaloneReference, "Connnection");
			dc.Toolbox.AddItem(ItemType.SCA_External, "Connnection");
			dc.Toolbox.AddItem(ItemType.BRule, "Connnection");
			dc.Toolbox.AddItem(ItemType.BRule_If, "Connnection");
			dc.Toolbox.AddItem(ItemType.BRule_And, "Connnection");
			dc.Toolbox.AddItem(ItemType.BRule_Or, "Connnection");
			dc.Toolbox.AddItem(ItemType.XOr, "Connnection");
			dc.Toolbox.AddItem(ItemType.BObjectIcon, "Connnection");
			dc.Toolbox.AddItem(ItemType.Activity, "Connnection");
			dc.Toolbox.AddItem(ItemType.Label, "Connnection");
			dc.Toolbox.AddItem(ItemType.Selector, "Connnection");
			dc.Toolbox.AddItem(ItemType.Mapping, "Connnection");
			dc.Toolbox.AddItem(ItemType.System, "Connnection");
			//}
			dc.DesignerControlTypes.Add(typeof(Designer.BObjects.BOProcessSymbol));
			dc.DesignerControlTypes.Add(typeof(Designer.BusinessServices.BusinessServiceSymbol));
			dc.DesignerControlTypes.Add(typeof(DomainSymbol));
			dc.DesignerControlTypes.Add(typeof(Designer.ITStructure.ITObjectSymbol));
			dc.DesignerControlTypes.Add(typeof(ExternalSymbol));
			dc.DesignerControlTypes.Add(typeof(Route));
			dc.DesignerControlTypes.Add(typeof(BusinessObjectSymbol));
			dc.DesignerControlTypes.Add(typeof(ServiceComponentSymbol));
			dc.DesignerControlTypes.Add(typeof(InterfaceSymbol));
			dc.DesignerControlTypes.Add(typeof(ReferenceSymbol));
			dc.DesignerControlTypes.Add(typeof(StandaloneReferenceSymbol));
			dc.DesignerControlTypes.Add(typeof(ServiceModuleSymbol));
			dc.DesignerControlTypes.Add(typeof(Designer.BRules.BusinessRuleSymbol));
			dc.DesignerControlTypes.Add(typeof(Designer.BRules.IFSymbol));
			dc.DesignerControlTypes.Add(typeof(Designer.BRules.THENELSESymbol));
			dc.DesignerControlTypes.Add(typeof(ANDSymbol));
			dc.DesignerControlTypes.Add(typeof(ORSymbol));
			dc.DesignerControlTypes.Add(typeof(XORSymbol));
			dc.DesignerControlTypes.Add(typeof(Designer.BRules.ActionSymbol));
			dc.DesignerControlTypes.Add(typeof(Designer.BusinessProcess.ActivitySymbol));
			dc.DesignerControlTypes.Add(typeof(OpenComposite.Base.Designer.Label));
			dc.DesignerControlTypes.Add(typeof(PolicyComponentSymbol));
			dc.DesignerControlTypes.Add(typeof(Designer.Selector.SelectorSymbol));
			dc.DesignerControlTypes.Add(typeof(SystemSymbol));
			dc.DesignerControlTypes.Add(typeof(MappingSymbol));

			dc.DesignerView.DropTypes.Add(typeof(Designer.BObjects.BOProcessSymbol));
			dc.DesignerView.DropTypes.Add(typeof(DomainSymbol));
			dc.DesignerView.DropTypes.Add(typeof(ExternalSymbol));
			dc.DesignerView.DropTypes.Add(typeof(BusinessObjectSymbol));
			dc.DesignerView.DropTypes.Add(typeof(ServiceModuleSymbol));
			dc.DesignerView.DropTypes.Add(typeof(Designer.BRules.BusinessRuleSymbol));
			dc.DesignerView.DropTypes.Add(typeof(OpenComposite.Base.Designer.Label));
			dc.DesignerView.DropTypes.Add(typeof(Designer.Selector.SelectorSymbol));
			dc.DesignerView.DropTypes.Add(typeof(SystemSymbol));

			return dc;
		}
		private IController initBusinessProcessDesigner(DockPanel dockPanel, IController parentController)
		{
			string designertext = "Business Process Designer";
			//string toolboxtext = "Business Process Toolbox";

			BusinessProcessDesignController dc = new BusinessProcessDesignController(_surfaceManager);
			dc.TabText = designertext;
			dc.ParentController = parentController as DesignController;

			//ToolboxDockContent tdc = findDockContent(toolboxtext, dockPanel) as ToolboxDockContent;
			//if ( tdc != null ) {
			//    dc.SetToolbox(tdc);
			//} else {
			//    dc.Toolbox.TabText = toolboxtext;

			dc.ToolboxCategory = "Process";
			dc.Toolbox.AddItem(ItemType.Activity, "Process");
			dc.Toolbox.AddItem(ItemType.Or, "Process");
			dc.Toolbox.AddItem(ItemType.XOr, "Process");
			dc.Toolbox.AddItem(ItemType.And, "Process");
			dc.Toolbox.AddItem(ItemType.While, "Process");
			//}
			dc.DesignerControlTypes.Add(typeof(ActivitySymbol));
			dc.DesignerControlTypes.Add(typeof(ORSymbol));
			dc.DesignerControlTypes.Add(typeof(XORSymbol));
			dc.DesignerControlTypes.Add(typeof(ANDSymbol));
			dc.DesignerControlTypes.Add(typeof(WhileSymbol));
			dc.DesignerControlTypes.Add(typeof(Route));

			dc.DesignerView.DropTypes.Add(typeof(ActivitySymbol));
			dc.DesignerView.DropTypes.Add(typeof(ORSymbol));
			dc.DesignerView.DropTypes.Add(typeof(XORSymbol));
			dc.DesignerView.DropTypes.Add(typeof(ANDSymbol));
			dc.DesignerView.DropTypes.Add(typeof(WhileSymbol));

			return dc;
		}
		private IController initWorkflowDesigner(DockPanel dockPanel, IController parentController)
		{
			Designer.Workflow.WorkflowController wfc =
				new OpenComposite.EII.Designer.Workflow.WorkflowController(dockPanel, _surfaceManager);

			return wfc;
		}
		private IController initBUSDesigner(DockPanel dockPanel, IController parentController)
		{
			string designertext = "Document Subscriptions";
			//string toolboxtext = "BUS Toolbox";

			BUSViewController dc = new BUSViewController(_surfaceManager);
			dc.TabText = designertext;
			dc.ParentController = parentController as DesignController;

			dc.SetToolbox(null);
			//ToolboxDockContent tdc = findDockContent(toolboxtext, dockPanel) as ToolboxDockContent;
			//if ( tdc != null ) {
			//    dc.SetToolbox(tdc);
			//} else {
			//    dc.Toolbox.TabText = toolboxtext;

			//    dc.Toolbox.AddItem(ItemType.BUSActivity);
			//}

			dc.DesignerControlTypes.Add(typeof(BUSSymbol));
			dc.DesignerControlTypes.Add(typeof(BUSActivitySymbol));
			dc.DesignerControlTypes.Add(typeof(BUSDocumentSymbol));
			dc.DesignerControlTypes.Add(typeof(BUSVariablesSymbol));
			dc.DesignerControlTypes.Add(typeof(Route));

			dc.DesignerView.DropTypes.Add(typeof(BUSActivitySymbol));
			dc.DesignerView.DropTypes.Add(typeof(BUSDocumentSymbol));

			return dc;
		}
		private IController initSystemDiagram(DockPanel dockPanel, IController parentController)
		{
			string designertext = "System Diagram";
			//string toolboxtext = "System Toolbox";

			DesignController dc = new DesignController(_surfaceManager);
			dc.TabText = designertext;
			dc.ParentController = parentController as DesignController;

			//ToolboxDockContent tdc = findDockContent(toolboxtext, dockPanel) as ToolboxDockContent;
			//if ( tdc != null ) {
			//    dc.SetToolbox(tdc);
			//} else {
			//    dc.Toolbox.TabText = toolboxtext;

			dc.ToolboxCategory = "System";
			dc.Toolbox.AddItem(ItemType.System, "System");
			dc.Toolbox.AddItem(ItemType.Composite, "System");
			dc.Toolbox.AddItem(ItemType.Component, "System");
			dc.Toolbox.AddItem(ItemType.OrchestrationComponent, "System");
			dc.Toolbox.AddItem(ItemType.RuleComponent, "System");
			dc.Toolbox.AddItem(ItemType.HumanComponent, "System");
			dc.Toolbox.AddItem(ItemType.UIComponent, "System");
			dc.Toolbox.AddItem(ItemType.SQLComponent, "System");
			dc.Toolbox.AddItem(ItemType.SCA_Export, "System");
			dc.Toolbox.AddItem(ItemType.SCA_Import, "System");
			dc.Toolbox.AddItem(ItemType.SCA_StandaloneReference, "System");
			dc.Toolbox.AddItem(ItemType.SCA_External, "System");
			dc.Toolbox.AddItem(ItemType.Selector, "System");
			dc.Toolbox.AddItem(ItemType.Mapping, "System");
			dc.Toolbox.AddItem(ItemType.Separator, "System");
			dc.Toolbox.AddItem(ItemType.BPolicy, "System");
			dc.Toolbox.AddItem(ItemType.Separator, "System");
			dc.Toolbox.AddItem(ItemType.ITObject, "System");
			dc.Toolbox.AddItem(ItemType.FA_Domain, "System");
			dc.Toolbox.AddItem(ItemType.FA_Service, "System");
			dc.Toolbox.AddItem(ItemType.BObject, "System");
			dc.Toolbox.AddItem(ItemType.Separator, "System");
			dc.Toolbox.AddItem(ItemType.Activity, "System");
			dc.Toolbox.AddItem(ItemType.Or, "System");
			dc.Toolbox.AddItem(ItemType.XOr, "System");
			dc.Toolbox.AddItem(ItemType.And, "System");
			dc.Toolbox.AddItem(ItemType.While, "System");
			dc.Toolbox.AddItem(ItemType.Separator, "System");
			dc.Toolbox.AddItem(ItemType.BObjectIcon, "System");
			dc.Toolbox.AddItem(ItemType.Label, "System");
			dc.Toolbox.AddItem(ItemType.Organization, "System");
			dc.Toolbox.AddItem(ItemType.OrgUnit, "System");
			dc.Toolbox.AddItem(ItemType.Role, "System");
			dc.Toolbox.AddItem(ItemType.User, "System");
			//}
			dc.DesignerControlTypes.Add(typeof(Designer.BObjects.BOProcessSymbol));
			dc.DesignerControlTypes.Add(typeof(Designer.BusinessServices.BusinessServiceSymbol));
			dc.DesignerControlTypes.Add(typeof(DomainSymbol));
			dc.DesignerControlTypes.Add(typeof(Designer.ITStructure.ITObjectSymbol));
			dc.DesignerControlTypes.Add(typeof(ExternalSymbol));
			dc.DesignerControlTypes.Add(typeof(Route));
			dc.DesignerControlTypes.Add(typeof(BusinessObjectSymbol));
			dc.DesignerControlTypes.Add(typeof(ServiceComponentSymbol));
			dc.DesignerControlTypes.Add(typeof(InterfaceSymbol));
			dc.DesignerControlTypes.Add(typeof(ReferenceSymbol));
			dc.DesignerControlTypes.Add(typeof(StandaloneReferenceSymbol));
			dc.DesignerControlTypes.Add(typeof(ServiceModuleSymbol));
			dc.DesignerControlTypes.Add(typeof(ORSymbol));
			dc.DesignerControlTypes.Add(typeof(XORSymbol));
			dc.DesignerControlTypes.Add(typeof(ANDSymbol));
			dc.DesignerControlTypes.Add(typeof(WhileSymbol));
			dc.DesignerControlTypes.Add(typeof(Designer.BRules.ActionSymbol));
			dc.DesignerControlTypes.Add(typeof(Designer.BusinessProcess.ActivitySymbol));
			dc.DesignerControlTypes.Add(typeof(OpenComposite.Base.Designer.Label));
			dc.DesignerControlTypes.Add(typeof(PolicyComponentSymbol));
			dc.DesignerControlTypes.Add(typeof(Designer.Selector.SelectorSymbol));
			dc.DesignerControlTypes.Add(typeof(SystemSymbol));
			dc.DesignerControlTypes.Add(typeof(MappingSymbol));
			dc.DesignerControlTypes.Add(typeof(OrchestrationComponentSymbol));
			dc.DesignerControlTypes.Add(typeof(RuleComponentSymbol));
			dc.DesignerControlTypes.Add(typeof(HumanComponentSymbol));
			dc.DesignerControlTypes.Add(typeof(UIComponentSymbol));
			dc.DesignerControlTypes.Add(typeof(SQLComponentSymbol));
			dc.DesignerControlTypes.Add(typeof(ExternalSymbol));
			dc.DesignerControlTypes.Add(typeof(Designer.ITStructure.ITObjectSymbol));
			dc.DesignerControlTypes.Add(typeof(PolicyComponentSymbol));
			dc.DesignerControlTypes.Add(typeof(OrgSymbol));
			dc.DesignerControlTypes.Add(typeof(OrgUnitSymbol));
			dc.DesignerControlTypes.Add(typeof(RoleSymbol));
			dc.DesignerControlTypes.Add(typeof(UserSymbol));

			dc.DesignerView.DropTypes.Add(typeof(SystemSymbol));
			dc.DesignerView.DropTypes.Add(typeof(ServiceModuleSymbol));
			dc.DesignerView.DropTypes.Add(typeof(ExternalSymbol));
			dc.DesignerView.DropTypes.Add(typeof(Designer.BObjects.BOProcessSymbol));
			dc.DesignerView.DropTypes.Add(typeof(DomainSymbol));
			dc.DesignerView.DropTypes.Add(typeof(BusinessObjectSymbol));
			dc.DesignerView.DropTypes.Add(typeof(OpenComposite.Base.Designer.Label));
			dc.DesignerView.DropTypes.Add(typeof(Designer.Selector.SelectorSymbol));
			dc.DesignerView.DropTypes.Add(typeof(ActivitySymbol));
			dc.DesignerView.DropTypes.Add(typeof(ORSymbol));
			dc.DesignerView.DropTypes.Add(typeof(XORSymbol));
			dc.DesignerView.DropTypes.Add(typeof(ANDSymbol));
			dc.DesignerView.DropTypes.Add(typeof(WhileSymbol));
			dc.DesignerView.DropTypes.Add(typeof(OrgSymbol));
			dc.DesignerView.DropTypes.Add(typeof(OrgUnitSymbol));
			dc.DesignerView.DropTypes.Add(typeof(RoleSymbol));
			dc.DesignerView.DropTypes.Add(typeof(UserSymbol));

			return dc;
		}
		private IController initOrgDiagram(DockPanel dockPanel, IController parentController)
		{
			string designertext = "Org Diagram";
			//string toolboxtext = "Org Toolbox";

			DesignController dc = new DesignController(_surfaceManager);
			dc.TabText = designertext;
			dc.ParentController = parentController as DesignController;

			//ToolboxDockContent tdc = findDockContent(toolboxtext, dockPanel) as ToolboxDockContent;
			//if ( tdc != null ) {
			//    dc.SetToolbox(tdc);
			//} else {
			//    dc.Toolbox.TabText = toolboxtext;

			dc.ToolboxCategory = "Organisation";
			dc.Toolbox.AddItem(ItemType.Label, "Organisation");
			dc.Toolbox.AddItem(ItemType.Organization, "Organisation");
			dc.Toolbox.AddItem(ItemType.OrgUnit, "Organisation");
			dc.Toolbox.AddItem(ItemType.Role, "Organisation");
			dc.Toolbox.AddItem(ItemType.User, "Organisation");
			//}
			dc.DesignerControlTypes.Add(typeof(OrgSymbol));
			dc.DesignerControlTypes.Add(typeof(OrgUnitSymbol));
			dc.DesignerControlTypes.Add(typeof(RoleSymbol));
			dc.DesignerControlTypes.Add(typeof(UserSymbol));

			dc.DesignerView.DropTypes.Add(typeof(OrgSymbol));
			dc.DesignerView.DropTypes.Add(typeof(OrgUnitSymbol));
			dc.DesignerView.DropTypes.Add(typeof(RoleSymbol));
			dc.DesignerView.DropTypes.Add(typeof(UserSymbol));

			return dc;
		}

		private DockContent findDockContent(string tabText, DockPanel dockPanel)
		{
			if ( dockPanel == null )
				return null;
			foreach ( DockContent dc in dockPanel.Contents ) {
				if ( dc.TabText == tabText ) {
					return dc;
				}
			}
			return null;
		}
		#endregion

		#region Event Handlers
		private void controller_Closed(object sender, EventArgs e)
		{
			IController ctrlr = sender as IController;
			if ( ctrlr != null )
				_lstController.Remove(ctrlr);
		}
		#endregion
		#endregion

		public IController CreateDesignController(DockPanel dockPanel, ItemType type)
		{
			return this.CreateDesignController(dockPanel, type, null);
		}
		public IController CreateDesignController(DockPanel dockPanel, ItemType type, IController parentController)
		{
			IController controller = null;
			switch ( type ) {
				case ItemType.BObject:
					controller = initBusinessObjectDesigner(dockPanel, parentController);
					break;
				//case ItemType.Service:
				////case ItemType.SCA_ServiceComponent:
				//case ItemType.SCA_ServiceModule:
				//    controller = initSCADesigner(dockPanel);
				//    break;
				case ItemType.System:
					controller = initSystemDiagram(dockPanel, parentController);
					break;
				case ItemType.SOBA:
					controller = initSOBADesigner(dockPanel, parentController);
					break;
				case ItemType.Composite:
					controller = initCompositeDesigner(dockPanel, parentController);
					break;
				case ItemType.Component:
					controller = initComponentDesigner(dockPanel, parentController);
					break;
				case ItemType.BRule:
				case ItemType.BPolicy:
					controller = initBRuleDesigner(dockPanel, parentController);
					break;
				case ItemType.FA_View:
					controller = initBusinessDiagramDesigner(dockPanel, parentController);
					break;
				case ItemType.ITObject:
					controller = initITStructureDiagram(dockPanel, parentController);
					break;
				case ItemType.Diagram:
					// controller = initConnectionDiagram(dockPanel, parentController);
					controller = initOrgDiagram(dockPanel, parentController);
					break;
				case ItemType.Organization:
					controller = initOrgDiagram(dockPanel, parentController);
					break;
				case ItemType.Business_Process:
					controller = initBusinessProcessDesigner(dockPanel, parentController);
					break;
				case ItemType.Workflow:
					controller = initWorkflowDesigner(dockPanel, parentController);
					break;
				case ItemType.BUS:
					controller = initBUSDesigner(dockPanel, parentController);
					break;
			}
			DesignController dc = controller as DesignController;
			if ( dc != null ) {
				dc.DesignerView.DesignerSite = new DesignerSite(_surfaceManager, null, null);
			}
			return controller;
		}
		public IController CreateDesignController(DockPanel dockPanel,
			RepositoryItemBaseEx item, int repositoryId)
		{
			ItemType type;
			if ( item is Diagram ) {
				type = ( (Diagram)item ).Type;
			} else {
				type = item.RepositoryItemType;
			}
			IController controller = null;
			foreach ( IController ctrlr in _lstController ) {
				if ( ctrlr.RepositoryItem == item ) {
					controller = ctrlr;
					break;
				}
			}
			if ( controller == null ) {
				RepositoryItemDesigner rid = RepositoryService.GetRepositoryItemDesigner(item);
				if ( rid != null && rid.HasControllers ) {
					DesignController dc = new DesignController(_surfaceManager);
					dc.Load(rid);
					controller = dc;
					if ( controller != null ) {
						controller.Closed += new EventHandler(controller_Closed);
						_lstController.Insert(0, controller);
					}
				} else {
					controller = CreateDesignController(dockPanel, type);
					if ( controller != null ) {
						controller.Closed += new EventHandler(controller_Closed);
						_lstController.Add(controller);
						// set diagram main item
						controller.Load(item, repositoryId, getDomainIDOfItem(item));
					}
				}
			}
			return controller;
		}

		public IController CreateDesignController(DockPanel dockPanel,
			ItemType typeDiagram, RepositoryItemBaseEx item, int repositoryId)
		{
			IController controller = null;
			foreach ( IController ctrlr in _lstController ) {
				if ( ctrlr.RepositoryItem == item && ctrlr.ControllerType == typeDiagram ) {
					controller = ctrlr;
					break;
				}
			}
			if ( controller == null ) {
				controller = CreateDesignController(dockPanel, typeDiagram);
				if ( controller != null ) {
					controller.Closed += new EventHandler(controller_Closed);
					_lstController.Add(controller);
					// set diagram main item
					controller.Load(typeDiagram, item, repositoryId, getDomainIDOfItem(item));
				}
			}
			return controller;
		}

		public IController CreateDesignControllerForRepositoryController(
			DockPanel dockPanel, IRepositoryItem repositoryItem, IController parentController)
		{
			ItemType type;
			if ( repositoryItem is Diagram ) {
				type = ( (Diagram)repositoryItem ).Type;
			} else {
				type = repositoryItem.RepositoryItemType;
			}
			IController controller = null;
			RepositoryItemBaseEx itemex = repositoryItem as RepositoryItemBaseEx;
			foreach ( IController ctrlr in _lstController ) {
				if ( ctrlr.RepositoryItem == itemex ) {
					controller = ctrlr;
					break;
				}
			}
			if ( controller == null ) {
				controller = CreateDesignController(dockPanel, type, parentController);
				if ( controller != null ) {
					controller.Closed += new EventHandler(controller_Closed);
					_lstController.Add(controller);
					// set diagram main item
					controller.Load(itemex, Global.Status.CurrentRepositoryId, getDomainIDOfItem(itemex));
				}
			}
			return controller;
		}

		/// <summary>
		/// Closes all open controllers.
		/// </summary>
		/// <param name="butThis">The IController to ignore on closing. Can be null.</param>
		public void CloseAllControllers(IController butThis)
		{
			//int i = 0;
			//while ( _lstController.Count > butThis == null ? 0 : 1 ) {
			//    if ( _lstController[i] == butThis ) { i++; continue; }
			//    _lstController[i].Close();
			//}
			for ( int i = _lstController.Count - 1; i >= 0; i-- ) {
				if ( _lstController[i] == butThis ) continue;
				_lstController[i].Close();
			}
			//for ( int i = 0; i < _lstController.Count; i++ ) {
			//    IController ctrl = _lstController[i];
			//    if ( ctrl == null ) continue;
			//    ctrl.Close();
			//}
		}
		#endregion

		#region Get Images, Icons and Keys of ItemTypes (TODO: Images, Icons)

		public string GetImageKey(ItemType type)
		{
			string key = "";
			switch ( type ) {
				case ItemType.GenericFolder:
					key = "folder_closed";
					break;
				case ItemType.Domain:
					key = "group";
					break;
				case ItemType.Noun:
					key = "field";
					break;
				case ItemType.Component:
				case ItemType.OrchestrationComponent:
				case ItemType.RuleComponent:
				case ItemType.HumanComponent:
				case ItemType.UIComponent:
				case ItemType.SQLComponent:
					key = "service";
					break;
				case ItemType.Verb:
					key = "verb";
					break;
				case ItemType.Operation:
				case ItemType.WebMethod:
					key = "method";
					break;
				case ItemType.BRule:
					key = "brule";
					break;
				case ItemType.BObject:
					key = "bobject";
					break;
				case ItemType.Composite:
					key = "capability";
					break;
				case ItemType.BPolicy:
					key = "policy";
					break;
				case ItemType.Diagram:
					key = "diagram";
					break;
				case ItemType.System:
					key = "system";
					break;
				case ItemType.SOBA:
					key = "diagram";
					break;
				case ItemType.Workflow:
					key = "workflow";
					break;
				case ItemType.Business_Process:
					key = "process";
					break;
				case ItemType.Mashup:
					key = "process";
					break;
				case ItemType.WebService:
					key = "webservice";
					break;
				case ItemType.RuleConstant:
					key = "constant";
					break;
				case ItemType.HumanActivity:
					key = "ha_component";
					break;
				case ItemType.Workflow_Method:
					key = "method";
					break;
				case ItemType.Workflow_Event:
					key = "event";
					break;
				case ItemType.Workflow_Field:
					key = "field";
					break;
				case ItemType.LogicalWebMethod:
					key = "logical_method";
					break;
				case ItemType.Capability:
					key = "capability";
					break;
				case ItemType.LogicalMethodGroup:
					key = "logical_method_group";
					break;
				case ItemType.Documentation:
					key = "documentation";
					break;
			}
			return key;
		}
		public string GetSelectedImageKey(ItemType type)
		{
			string key = "";
			switch ( type ) {
				case ItemType.GenericFolder:
					key = "folder_open";
					break;
				case ItemType.Domain:
					key = "group";
					break;
				case ItemType.Noun:
					key = "field";
					break;
				case ItemType.Component:
				case ItemType.OrchestrationComponent:
				case ItemType.RuleComponent:
				case ItemType.HumanComponent:
				case ItemType.UIComponent:
				case ItemType.SQLComponent:
					key = "service";
					break;
				case ItemType.Verb:
					key = "verb";
					break;
				case ItemType.Operation:
				case ItemType.WebMethod:
					key = "method";
					break;
				case ItemType.BRule:
					key = "brule";
					break;
				case ItemType.BObject:
					key = "bobject";
					break;
				case ItemType.Composite:
					key = "capability";
					break;
				case ItemType.BPolicy:
					key = "policy";
					break;
				case ItemType.Diagram:
					key = "diagram";
					break;
				case ItemType.System:
					key = "system";
					break;
				case ItemType.SOBA:
					key = "diagram";
					break;
				case ItemType.Workflow:
					key = "workflow";
					break;
				case ItemType.Business_Process:
					key = "process";
					break;
				case ItemType.Mashup:
					key = "process";
					break;
				case ItemType.WebService:
					key = "webservice";
					break;
				case ItemType.RuleConstant:
					key = "constant";
					break;
				case ItemType.HumanActivity:
					key = "ha_component";
					break;
				case ItemType.Workflow_Method:
					key = "method";
					break;
				case ItemType.Workflow_Event:
					key = "event";
					break;
				case ItemType.Workflow_Field:
					key = "field";
					break;
				case ItemType.LogicalWebMethod:
					key = "logical_method";
					break;
				case ItemType.Capability:
					key = "capability";
					break;
				case ItemType.LogicalMethodGroup:
					key = "logical_method_group";
					break;
				case ItemType.Documentation:
					key = "documentation";
					break;
			}
			return key;
		}

		// TODO: static methods for Images and Icons

		#endregion

		#region RepositoryMode

		public enum RepositoryMode
		{
			Complete,
			CompositeDesigner
		}
		private RepositoryMode _repositoryMode;
		public RepositoryMode Mode
		{
			get { return _repositoryMode; }
			set { _repositoryMode = value; }
		}

		#endregion

		#region Others
		// public methods
		public static string GetIdentifier(string text)
		{
			string name = Regex.Replace(text, "[^0-9a-zA-Z_]", "_");
			name = name.TrimEnd('_');
			return name;
		}
		public bool IsItemNameAvailable(IRepositoryItem item, string newName)
		{
			DataTable dt = Global.Data.SearchRepositoryItems(
				Global.Status.CurrentDomainId, item.RepositoryItemType,
				newName, null, true);
			if ( dt != null && dt.Rows.Count > 0 ) {
				foreach ( DataRow row in dt.Rows ) {
					if ( (int)row["id"] != item.ID ) {
						return false;
					}
				}
			}
			return true;
		}

		// private variables
		private RepositorySurfaceManager _surfaceManager;

		// private methods
		private int getDomainIDOfItem(IRepositoryItem item)
		{
			int domainId = 0;
			DataTable dt = Global.Data.GetRepositoryParentsOfType(item.RepositoryItemType, item.ID, ItemType.Domain);
			if ( dt != null && dt.Rows.Count > 0 ) {
				domainId = (int)dt.Rows[0]["parent_id"];
			}
			return domainId;
		}
		private ItemType getItemTypeFromIRepositoryItemClass<T>() where T : class, IRepositoryItem
		{
			ItemType type = ItemType.Undefined;
			object[] attribs = typeof(T).GetCustomAttributes(typeof(RepositoryItemAttribute), false);
			foreach ( object attrib in attribs ) {
				RepositoryItemAttribute ria = attrib as RepositoryItemAttribute;
				if ( ria != null ) {
					type = ria.ItemType;
					break;
				}
			}
			if ( type == ItemType.Undefined ) {
				throw new Exception(
					string.Format("The type '{0}' does not include a valid RepositoryItemAttribute.",
								  typeof(T).FullName));
			}
			return type;
		}
		#endregion

		#region IServiceProvider Members

		public object GetService(Type serviceType)
		{
			if ( _surfaceManager != null )
				return _surfaceManager.GetService(serviceType);
			else
				return null;
		}
		public T GetService<T>() where T : class
		{
			return GetService(typeof(T)) as T;
		}

		#endregion

		#region IRepositoryChangeService Members

		public void OnRepositoryChanging(IRepositoryItem repositoryItem,
										 MemberInfo member, object newValue)
		{
			Services.RepositoryChangingEventHandler tmp = this.RepositoryChanging;
			if ( tmp != null ) {
				tmp(this,
					new OpenComposite.EII.Services.RepositoryChangingEventArgs(repositoryItem, member, newValue));
			}
		}

		public void OnRepositoryChanged(IRepositoryItem repositoryItem,
										MemberInfo member,
										object oldValue, object newValue)
		{
			Services.RepositoryChangedEventHandler tmp = this.RepositoryChanged;
			if ( tmp != null ) {
				tmp(this,
					new Services.RepositoryChangedEventArgs(repositoryItem, member, oldValue, newValue));
			}
			if ( member.Name == "Name" ) {
				OnRepositoryRenamed(repositoryItem, oldValue as string, newValue as string);
			}
		}

		public event OpenComposite.EII.Services.RepositoryEventHandler RepositoryAdding = null;
		public event OpenComposite.EII.Services.RepositoryEventHandler RepositoryAdded = null;

		public event OpenComposite.EII.Services.RepositoryChangingEventHandler RepositoryChanging = null;
		public event OpenComposite.EII.Services.RepositoryChangedEventHandler RepositoryChanged = null;

		public event OpenComposite.EII.Services.RepositoryEventHandler RepositoryRemoving = null;
		public event OpenComposite.EII.Services.RepositoryEventHandler RepositoryRemoved = null;

		public event OpenComposite.EII.Services.RepositoryRenameEventHandler RepositoryRenamed = null;

		protected virtual void OnRepositoryChanging(Services.RepositoryChangingEventArgs e)
		{
			Services.RepositoryChangingEventHandler tmp = this.RepositoryChanging;
			if ( tmp != null ) {
				tmp(this, e);
			}
		}
		protected virtual void OnRepositoryChanged(Services.RepositoryChangedEventArgs e)
		{
			Services.RepositoryChangedEventHandler tmp = this.RepositoryChanged;
			if ( tmp != null ) {
				tmp(this, e);
			}
			if ( e.Member != null && e.Member.Name == "Name" ) {
				OnRepositoryRenamed(e.RepositoryItem, e.OldValue as string, e.NewValue as string);
			}
		}
		protected virtual void OnRepositoryAdding(IRepositoryItem repositoryItem)
		{
			Services.RepositoryEventHandler tmp = this.RepositoryAdding;
			if ( tmp != null ) {
				tmp(this, new OpenComposite.EII.Services.RepositoryEventArgs(repositoryItem));
			}
		}
		protected virtual void OnRepositoryAdded(IRepositoryItem repositoryItem)
		{
			Services.RepositoryEventHandler tmp = this.RepositoryAdded;
			if ( tmp != null ) {
				tmp(this, new OpenComposite.EII.Services.RepositoryEventArgs(repositoryItem));
			}
		}
		protected virtual void OnRepositoryRemoving(IRepositoryItem repositoryItem)
		{
			Services.RepositoryEventHandler tmp = this.RepositoryRemoving;
			if ( tmp != null ) {
				tmp(this, new OpenComposite.EII.Services.RepositoryEventArgs(repositoryItem));
			}
		}
		protected virtual void OnRepositoryRemoved(IRepositoryItem repositoryItem)
		{
			Services.RepositoryEventHandler tmp = this.RepositoryRemoved;
			if ( tmp != null ) {
				tmp(this, new OpenComposite.EII.Services.RepositoryEventArgs(repositoryItem));
			}
		}
		protected virtual void OnRepositoryRenamed(IRepositoryItem repositoryItem,
												   string oldName, string newName)
		{
			Services.RepositoryRenameEventHandler tmpRenamed = this.RepositoryRenamed;
			if ( tmpRenamed != null ) {
				tmpRenamed(this,
						   new Services.RepositoryRenameEventArgs(repositoryItem, oldName, newName));
			}
		}
		#endregion

		#region Static Members
		internal static IDesigner GetDesigner(IComponent component)
		{
			IDesigner designer = null;
			if ( component != null ) {
				object[] attribs = component.GetType().GetCustomAttributes(typeof(DesignerAttribute), false);
				if ( attribs == null || attribs.Length == 0 ) {
					attribs = component.GetType().GetCustomAttributes(typeof(DesignerAttribute), true);
				}
				if ( attribs != null && attribs.Length > 0 ) {
					foreach ( object attrib in attribs ) {
						DesignerAttribute da = attrib as DesignerAttribute;
						if ( da != null ) {
							Type t = Type.GetType(da.DesignerTypeName);
							if ( t != null ) {
								ConstructorInfo ctor = t.GetConstructor(Type.EmptyTypes);
								if ( ctor != null ) {
									designer = ctor.Invoke(new object[0]) as IDesigner;
									if ( designer != null ) {
										designer.Initialize(component);
										break;
									}
								}
							}
						}
					}
				}
			}
			return designer;
		}
		internal static RepositoryItemDesigner GetRepositoryItemDesigner(IRepositoryItem repositoryItem)
		{
			return RepositoryService.GetDesigner(repositoryItem) as RepositoryItemDesigner;
		}
		private void WorkflowHelpers_AssignWorkflow(object sender, EventArgs e)
		{
			RepositorySurface surface = _surfaceManager.ActiveDesignSurface as RepositorySurface;
			if ( surface == null || surface.Controller == null || surface.Controller.RepositoryItem == null ) return;
			LogicalCapabilityActivity logAct = sender as LogicalCapabilityActivity;
			Repository.Workflow wf = null;
			try {
				wf = Global.Data.RepositoryService.GetItem<Repository.Workflow>((int)logAct.UserData["workflow"]);
			} catch { return; }
			LogicalActivity la = Global.Data.RepositoryService.GetItem<LogicalActivity>(logAct.LogicalActivityId);
			if ( la == null ) return;
			Operation op;
			if ( la.OperationID < 1 ) {
				IRepositoryItem parent = null;
				op = GetNewItem<Operation>(false, ref parent);
				if ( op == null ) return;
				la.OperationID = op.ID;
			} else { op = GetItem<Operation>(la.OperationID); }
			op.WorkflowId = surface.Controller.RepositoryItem.ID;
			op.ExposedWorkflowId = wf.ID;
			op.ExposedVerbID = la.VerbID;
			op.Save();
			la.Save();
		}

		#endregion

		public void RunTrackingMonitor()
		{
			FormTrackingMonitor frm = new FormTrackingMonitor();
			frm.Show();
		}
	}

	#region Class: ItemChangedEventArgs : Base: EventArgs
	public class ItemChangedEventArgs : EventArgs
	{
		public ItemChangedEventArgs(RepositoryItemBase item, string changedMembers, bool isDeleted)
		{
			_item = item;
			_changedMembers = changedMembers;
			_isDeleted = isDeleted;
		}
		private readonly RepositoryItemBase _item;
		public RepositoryItemBase Item
		{
			get { return _item; }
		}
		private readonly string _changedMembers;
		public string ChangedMembers
		{
			get { return _changedMembers; }
		}
		private bool _isDeleted;
		public bool IsDeleted
		{
			get { return _isDeleted; }
		}

	}
	#endregion
}
